Part Number Hot Search : 
2N2237 0033EKX1 FMM5701X 00306 1902X352 5KE300CA 1771I 100K1
Product Description
Full Text Search
 

To Download M306KAFCLRP Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
 M16C/6KA Group
SINGLE-CHIP 16-BIT CMOS MICROCOMPUTER Description Description
REJ03B0100-0100Z Rev.1.00 Jul 16, 2004
The M16C/6KA group of single-chip microcomputers are built using the high-performance silicon gate CMOS process using a M16C/60 Series CPU core and are packaged in a 144-pin plastic molded QFP. These single-chip microcomputers operate using sophisticated instructions featuring a high level of instruction efficiency. To communicate with host CPU, the LPC bus interface is built in. In this way, this MCU can work as slave controller in the personal computer system.
Features
* Memory capacity ........................................ ROM 128K bytes RAM 5K bytes * The Min. time of instruction execution ....... 62.5ns (f(XIN)=16MHz, with 0 wait, Vcc=3.3V) * Supply voltage ........................................... 3.0 to 3.6V (f(XIN)=16MHZ with 0 wait) * Supply voltage for Program/Erase ............. 3.0 to 3.6V (CPU reprogram mode 0, Internal clock=8MHZ with 1 wait) (CPU reprogram mode 1, Internal clock=4MHZ with 1 wait) * Low power consumption ............................ 52.8mW ( f(XIN)=16MHZ, with 0 wait, VCC = 3.3V) * Interrupts .................................................... 32 internal and 16 external interrupt sources, 4 software interrupt sources; 7 levels (including key input interrupt) * Key input interrupts ...................................... 2 (8 inputs shared with 1 interrupt request X 1; 8 inputs (with event latch) shared with1 interrupt request X 1) * Multifunction 16-bit timer ............................ 5 output timers + 6 input timers * Serial I/O (Serial interface) ........................ 3 channels (1 for UART or clock synchronous, 2 for clock synchronous) * Host interface ............................................. LPC bus interface X 4 * A-D converter (A/D converter) ................... 10 bits X 8 channels (Expandable up to 10 channels) * PWM .......................................................... 8 bits X 6 channels * Watchdog timer .......................................... 1 * I2C bus interface ........................................ 3 channels * PS/2 interface ............................................ 3 channels * Serial interrupt output ................................ 6 factors (2 fixed factors, 4 programmable factors) * Programmable I/O ..................................... 129 _______ * Input port .................................................... 1 (P85 shared with NMI pin) * Clock generating circuit ............................. 1 built-in clock generation circuit (built-in feedback resistor, and external ceramic)
Applications
Notebook PC, others
Specifications written in this manual are believed to be accurate, but are not guaranteed to be entirely free of error. Specifications in this data sheet may be changed for functional or performance improvements. Please make sure your manual is the latest edition.
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 1 of 266
M16C/6KA Group
Description
------Table of Contents-----Central Processing Unit (CPU) ..................... 13 Reset ............................................................. 16 Processor Mode ............................................ 26 Clock Generating Circuit ............................... 29 Protection ...................................................... 37 Interrupts ....................................................... 38 Watchdog Timer ............................................ 65 Timer ............................................................. 67 Serial I/O (Serial interface) ............................ 85 A-D Converter (A/D converter) .................... 111 PWM Output Circuit .................................... 121 LPC Bus Interface ....................................... 125 Serial interrupt output .................................. 143 I2C-BUS Interface ........................................ 154 PS2 Interface .............................................. 185 Programmable I/O Ports ............................. 200 Electrical Characteristics ............................. 221 Flash Memory Version ................................ 234
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 2 of 266
M16C/6KA Group
Description
The differences in M16C/6K (144-pin) group
Type name M306K7F8LRP(In mass production) 144-pin 3K bytes NEW DINOR Flash memory 68K bytes User ROM area Address 0EF00016 - 0FFFFF16 Boot ROM area Address 0FF00016 - 0FFFFF16 Flash memory recognition register After reset 000000002 Flash memory control register After reset XX0000012 M306K9FCLRP (In mass production) 144-pin 5K bytes NEW DINOR Flash memory 128K bytes User ROM area Address 0E000016 - 0FFFFF16 Boot ROM area Address 0FF00016 - 0FFFFF16 Flash memory recognition register After reset XXXXXX102 Flash memory control register After reset 000000012 Vcc 3.0 - 3.6V FVCC 3.0 - 3.6V The input pin of power supply for program/erase M306KAFCLRP(Under development) 144-pin 5K bytes NEW DINOR Flash memory 128K bytes User ROM area Address 0E000016 - 0FFFFF16 Boot ROM area Address 0FF00016 - 0FFFFF16 Flash memory recognition register After reset XXXXXX112 Flash memory control register After reset 000000012
Pin numbers RAM
ROM
Built-in ROM area
Address 03B416
Address 03B716
The power supply for program/erase
Vcc
3.0 - 3.6V
Vcc
3.0 - 3.6V
FVCC pin
Not exist
Not exist
PWM output circuit I2C bus interface
14-bit X 4
8-bit X 6
8-bit X 6 3 channels (I2C bus interface pin of Channel 1 and 2 can changed.) 8 inputs shared with 1 interrupt request X 1 8 inputs (with event latch) shared with 1 interrupt request X 1 Detected in either of the edges by the edge selection Can be selected with 1 bit unit Not exist
2 channels
3 channels
Key input interrupt
8 inputs shared with 1 interrupt request X 1 8 inputs (with event latch) shared with 1 interrupt request X 1 Detected only in the falling edge Can not be selected with 1 bit unit
8 inputs shared with 1 interrupt request X 1 8 inputs (with event latch) shared with 1 interrupt request X 1 Detected in either of the edges by the edge selection Can be selected with 1 bit unit Exist (2 channels)
DMAC
Exist (2 channels)
D/A converter Comparator Circuit Interrupts
Exist (8-bit X 2 channels) Exist (8 channels) 31 vector
Exist (8-bit X 2 channels) Exist (8 channels) 31 vector
Not exist Not exist 45 vector (add OBE int.)
Serial I/O
* UART or clock synchronous X 3 * clock synchronous X 2
* UART or clock synchronous X 3 * clock synchronous X 2
* UART or clock synchronous X 1 * clock synchronous X 2
Clock generation circuits
2 circuits
2 circuits
1 circuit
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 3 of 266
M16C/6KA Group
Description
Pin configuration
Fig. AA-1 shows the pin configuration (top view). PIN CONFIGURATION (top view)
P11 P12 P13 P14/INT71/CTS11/RTS11/CLKS11 P15/INT81/CLK11 P16/INT91/RXD11 P17/INT101/TXD11 P20 P21 P22 P23 P24 P25 P26 P27 VSS P30/LAD0 VCC P127 P31/LAD1 P32/LAD2 P33/LAD3 P34/LFRAME P35/LRESET P36/LCLK P37 P130 P131 P132 P133 P134 P135 P136 P137 P40/ TA00OUT/OBF00/PWM41 P41/TA10OUT/PWM51
108 107 106 105 104 103 102 101 100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82
P10 P126 P125/INT111 P124/INT102 P123/INT92 P122/INT82 P121/INT72 P120/INT61 P07 P06 P05 P04 P03 P02 P01 P00 P117 P116 P115 P114 P113 P112 P111/F1OUT1 P110/F1OUT0 P107/AN7/INT110 P106/AN6/INT100 P105/AN5/INT90 P104/AN4/INT80 P103/AN3/INT70 P102/AN2 P101/AN1 AVSS P100/AN0 VREF AVcc P97/ADTRG/SIN40/INT60
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 1 2345 678 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
81 80 79 78 77 76 75 74 73
72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57
M306KAFCLRP
56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37
P42/TA20OUT/GATEA20 P43/OBF01/SERIRQ P44/PWM01/OBF1 P45/PWM11/OBF2/PRST P46/PWM21/OBF3/CLKRUN VCC P47/PWM31 VSS P140/KI10 P141/KI11 P142/KI12 P143/KI13 P144/KI14 P145/KI15 P146/KI16 P147/KI17 P50/KI00 P51/KI01 P52/KI02 P53/KI03 P54/KI04 P55/KI05 P56/KI06 P57 /CLKOUT/KI07 P150/TA01OUT/CLK31 P151/TA11OUT/SIN31 P152/TA21OUT/SOUT31 P60/SDA0 P61/SCL0 P62/SDA10 P63/SCL10 P64/CTS10/RTS10/CLKS10 P65/CLK10 P66/RXD10/TA3OUT P67/TXD10/TA4OUT P70/PS2A0
Fig. AA-1 Pin configuration (top view)
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 4 of 266
P96/ANEX1/SOUT40/PWM30 P95/ANEX0/CLK40/PWM20 P94/TB40IN/PWM10 P93/TB30IN/PWM00 P92/SOUT30/INT5 P91/SIN30/INT4 P90/CLK30/INT3 P161/TB41IN/PWM50 P160/TB31IN/PWM40 P157/SIN41 P156/SOUT41 P155/CLK41 P154 P153 M1 M0 P87 P86 RESET XOUT VSS XIN VCC P85/NMI P84/TB2IN/SCL21 P83/TB1IN/SDA21 P82/TB0IN/SCL11 P81/TA4IN/SDA11 P80/ICCK P77/TA3IN/SCL20 P76/SDA20 P75/TA2IN/INT2/PS2B2 P74/INT1/PS2B1 P73/TA1IN/INT0/PS2B0 P72/PS2A2 P71/TA0IN/TB5IN/PS2A1
Package: 144PFB-A
M16C/6KA Group
Description
Block Diagram
Fig.AA-2 is a block diagram of the M16C/6KA (144-pin version) group.
8 8 8 8 8 8 8
I/O ports
Port P0
Port P1
Port P2
Port P3
Port P4
Port P5
Port P6
Port P7
Internal peripheral function
Timer Timer TA0(16 bits) Timer TA1(16 bits) Timer TA2(16 bits) Timer TA3(16 bits) Timer TA4(16 bits) Timer TB0(16 bits) Timer TB1(16 bits) Timer TB2(16 bits) Timer TB3(16 bits) Timer TB4(16 bits) Timer TB5(16 bits) Watchdog timer (15 bits) PS2 interface (3 channels) Serial interrupt output (6 factors) A-D converter (10 bits x 8 channels Expandable up to 10 channels) UART/clock synchronous SI/O (8 bits x 1 channel)
Host interface (LPC bus interface x 4 channels)
System clock generator XIN-XOUT
8
Port P8
Clock synchronous SI/O (8 bits x 2channels)
2
7
I C bus interface (3 channels) PWM output (8 bits x 6channels)
Port P85 Port P9
M16C/60 series 16-bit CPU core
Registers
R0H R0 R0H R0L R1H R1 L R1H R1L RL R2 R 2 R3 A 3 A0 A 0 A1 FB 1 FB SB
Memory
ROM (Note1) RAM (Note2)
8
Program counter
PC
Stack pointer
ISP USP
Port P10
8
Vector table
INTB
Flag register
FLG
Multiplier
Port P16
Port P15
Port P14
Port P13
Port P12
Port P11
2
8
8
8
8
8
Note1 : ROM size depends on MCU type. Note2 : RAM size depends on MCU type.
Fig.AA-2 Block diagram of M16C/6KA (144-pin version) group
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 5 of 266
M16C/6KA Group
Description
Performance Outline
Table AA-1 is a performance outline of M16C/6KA (144-pin version) group. Table AA-1 Performance outline of M16C/6KA (144-pin version) group Item Performance Number of basic instructions 91 instructions The Min. time of instruction execution 62.5ns (f(XIN)=16MHz, with 0 wait, Vcc=3.3V) Memory ROM (See the figure of ROM Expansion) capacity RAM 5K bytes I/O port P0 to P10 (except P85) 8 bits x 10, 7 bits x 1 P11 to P16 8 bitsx5, 2 bitsx1 Input port P85 1 bit x 1 Multifunction TA0, TA1, TA2, TA3, TA4 16 bits x 5 timer TB0, TB1, TB2, TB3, TB4, TB5 16 bits x 6 Serial I/O UART1 (UART or clock synchronous) x 1 SI/O3, SI/O4 A-D converter Watchdog timer Interrupt Host interface PWM I2C bus interface PS2 interface Serial interrupt output Clock generating circuit Power consumption I/O I/O withstand voltage characteristics Output current Device configuration Package (Clock synchronous) x 2 10 bits x (8 + 2) channels 15 bits x 1 (with prescaler) 32 internal and 16 external sources, 4 software sources, 7 levels 4 channels (LPC bus interface) 8 bits x 6 3 channels 3 channels 6 factors (2 fixed factors, 4 programmable factors) 1 built-in clock generation circuit
(built-in feedback resistor, and external ceramic)
52.8mW (3.3V, f(XIN)=16MHz, with 0 wait) 3.3V 5mA CMOS high performance silicon gate 144-pin plastic mold QFP
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 6 of 266
M16C/6KA Group
Description
Renesas plans to release the following products in the M16C/6KA (144-pin version) group: (1) Support for flash memory version (2) ROM capacity (3) Package 144PFB-A : Plastic molded QFP(flash memory version)
ROM Size (Byte) External ROM 256K 128K 96K 80K 64K 32K Mask ROM version Flash version
M306KAFCLRP
Fig.AA-3 ROM expansion
Table AA-2 Product list Type No. M306KAFCLRP ROM size RAM size 128 bytes 5K bytes Package type 144PFB-A Host Interface LPC
From July 2004 up to now Remarks Flash memory (NEW DINOR) version
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 7 of 266
M16C/6KA Group
Description
Type No. M30 6KA F C XXX RP
Package type RP : 144PFB-A
ROM No. ROM type C : 128Kbytes
Memory type F : Flash version
M16C/6KA Group M16C Family
Fig.AA-4 Type No., memory size, and package
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 8 of 266
M16C/6KA Group
Pin Description
Pin Description Pin name Signal name Vcc, Vss
____________
I/O type
Function Apply 3.0 to 3.6 V to VCC . Apply 0V to VSS
Power supply input Reset input Clock input Clock output Input Input Output
RESET XIN XOUT
A "L" on this input resets the microcomputer. These pins are provided for the main clock generating circuit. Connect a ceramic resonator between the XIN and the XOUT pins. To use an externally derived clock, input it to the XIN pin and leave the XOUT pin open. Connect to VSS This pin is a power supply input for the A-D converter. Connect this pin to VCC. This pin is a power supply input for the A-D converter. Connect this pin to VSS.
M0,M1 AVCC AVSS VREF P00 to P07
Chip mode setting Analog power supply input Analog power supply input Reference voltage input I/O port P0
Input
Input
This pin is a reference voltage input for the A-D converter.
Input/output This is an 8-bit CMOS I/O port. It has an input/output port direction register that allows the user to set each pin for input or output individually. When set for input, the user can specify in units of four bits via software whether or not they are tied to a pull-up resistor. This port supports CMOS input level. And output type supports CMOS 3 state or N channel open drain selectable. Input/output This is an 8-bit I/O port equivalent to P0. Pins in this port also function as external interrupt pins or UART1 I/O pin selected by software. Input/output This is an 8-bit I/O port equivalent to P0. (Except that output type just supports CMOS 3 state only). P20-P27 are available for directly driving LED's. Input/output This is an 8-bit I/O port equivalent to P0. (Except that output type just supports CMOS 3 state only). The port can be used for LPC bus interface I/O pins by software selection. Input/output This is an 8-bit I/O port equivalent to P0. (Except that output type just supports CMOS 3 state only). By software selecting, the port can also be used for LPC bus interface I/O pins, Timer A0 to A2 output pins PWM output pins or serial interrupt output I/O pins. P40 to P46 pins' level can be read regardless the setting of input port or output port. If P40 or P43 are used for output ports, the function that clears P40 or P43 to "0" after the read of output data buffer from host CPU is available. Input/output This is an 8-bit I/O port equivalent to P0. (Except that output type is CMOS 3 state only). Key on wake interrupt 0 input function support. P57 in this port outputs a divide-by-8 or divide-by-32 clock of XIN selected by software.
P10 to P17
I/O port P1
P20 to P27
I/O port P2
P30 to P37
I/O port P3
P40 to P47
I/O port P4
P50 to P57
I/O port P5
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 9 of 266
M16C/6KA Group
Pin Description
Pin Description Pin name P60 to P67 Signal name I/O port P6 I/O type Function
Input/output This is an 8-bit I/O port equivalent to P0. (Except that P60 to P63's output type is N channel open drain only; P64 to P67's output type is CMOS 3 state only; P60 to P63 no internal pull-up register support.) By software selecting, this port can be used for I2C-BUS interface, UART1 input/output pin, timerA3, A4 output pin. When P60 to P63 used as I2C-BUS interface SDA, SCL, the input level of these pins are CMOS/ SMBUS selectable. Input/output This is an 8-bit I/O port equivalent to P0. (Except that P70 to P77 output type is N channel open drain only; no internal pull-up register support.) By software selecting, this port can be used for external interrupt input pin, timerA0 to A3 and timer B5 input pin, PS2 interface input/output pin, I2C interface input/output pin. P70 to P75 pins' level can be read regardless of the setting of input port or output port. Input/output Input/output Input/output Input P80 to P84, P86, and P87 are I/O ports with the same functions as P0. (Except that P86 to P87's output type is CMOS 3 state only; P80 to P84's output type is N channel open drain only; P85 is input port only; the P80 to P84 and P85 are no internal pull-up register support.) By software selecting, this port can be used for timer A4, B0 to B2, I2C-BUS interface I/O pins. The input level of P81 to P84 and SDA, SCL inputs can be switched to CMOS/SMBUS when these pins function as I2C bus interface. P85 is an ______ ______ input-only port that also functions for NMI. The NMI interrupt is generated when the input at this pin changes from "H" to ______ "L". The NMI function cannot be cancelled using software. Input/output This is an 8-bit I/O port equivalent to P0. (Except that output type is CMOS 3 state only.) By software selecting, the port can be used for external interrupt, timer B3 to B4, A-D converter extended input pins, A-D trigger, SI/O3, SI/O4 I/O pins, PWM, output pins. Input/output This is an 8-bit I/O port equivalent to P0. (Except that output type is CMOS 3 state only.) If the ports are set to input mode, the pull-up resistor can be set in bit unit. By software selecting, the port can be used for A-D converter, external interrupt input pins.
P70 to P77
I/O port P7
P80 to P84, P86, P87, P85
I/O port P8
I/O port P85
P90 to P97
I/O port P9
P100 to P107
I/O port P10
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 10 of 266
M16C/6KA Group
Pin Description
Pin Description Pin name P110 to P117 Signal name I/O port P11 I/O type Function
Input/output This is an 8-bit I/O port equivalent to P0. By software selecting, P110, P111 also function as clock output pins, which the frequency is the same with XIN. Input/output This is an 8-bit I/O port equivalent to P0. (Except that output type is CMOS 3 state only.) By software selecting, this port can be used for external interrupt input pin. Input/output This is an 8-bit I/O port equivalent to P0. (Except that output type is N channel open drain only; no internal pull-up register support.) Input/output This is an 8-bit I/O port equivalent to P0. The port can be used for key on wake-up interrupt 1 input pins. P140 to P143 are available for directly driving LED's. In input mode, the pull-up register can be set in one bit unit by software. Input/output This is an 8-bit I/O port equivalent to P0. (Except that output type is CMOS 3 state only.) By software selecting, these ports can be used for timer A0 to A2's output or SI/O3 and SI/O4 I/O pins. Input/output This is an 2-bit I/O port equivalent to P0. (Except that output type is CMOS 3 state only.) By software selecting, this port can be used for timer B3 and B4 input or PWM output pin.
P120 to P127
I/O port P12
P130 to P137
I/O port P13
P140 to P147
I/O port P14
P150 to P157
I/O port P15
P160, P161
I/O port P16
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 11 of 266
M16C/6KA Group
Memory
Operation of Functional Blocks
The M16C/6KA (144-pin version) group accommodates certain units in a single chip. These units include ROM and RAM to store instructions and data and the central processing unit (CPU) to execute arithmetic/ logic operations. Also peripheral units such as timers, serial I/O, A-D converter, host bus interface, PWM output, I2C BUS interface, PS2 interface and I/O ports are included. The following explains each unit.
Memory
Fig.CA-1 is the memory map. The address space extends up to 1M bytes from address 0000016 to FFFFF16. There is 128K bytes of internal ROM from E000016 to FFFFF16. The vector table for fixed interrupts such as _______ the reset and NMI are mapped from FFFDC16 to FFFFF16. The starting address of the interrupt routine is stored here. The address of the vector table for timer interrupts, etc., can be set as desired using the internal register (INTB). See the section on interrupts for details. From 0040016 to the address increasing direction RAM is allocated. For example, in the M306KAFCLRP, 5K bytes of internal RAM is mapped to the space from 0040016 to 017FF16. In addition to storing data, the RAM also stores the stack used when calling subroutines and when interrupts are generated. The SFR area is mapped from 0000016 to 003FF16. This area accommodates the control registers for peripheral devices such as I/O ports, A-D converter, serial I/O, and timers, etc. Fig.CA-2 to CA-5 are location of peripheral unit control registers. Any part of the SFR area that is not occupied is reserved and cannot be used for other purposes. The special page vector table is mapped from FFE0016 to FFFDB16. If the starting addresses of subroutines or the destination addresses of jumps are stored here, subroutine call instructions and jump instructions can be used as 2-byte instructions, reducing the number of program steps.
0000016
SFR area
For details, see Fig.CA-2 to Fig.CA-4
0040016 Internal RAM area FFE0016 017FF16 Special page vector table FFFDC16
Undefined instruction
Inhibited
Overflow BRK instruction Address match Single step
E000016 Internal ROM area FFFFF16 FFFFF16
Watchdog timer DBC NMI Reset
Fig.CA-1 Memory map
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 12 of 266
M16C/6KA Group
CPU
Central Processing Unit (CPU)
The CPU has a total of 13 registers shown in Fig.BA-1 Seven of these registers (R0, R1, R2, R3, A0, A1, and FB) come in two sets; therefore, these have two register banks.
b15
b8 b7
b0
R0(Note)
H
L
b15
b8 b7
b0
b19
b0
R1(Note)
H
L Data registers
PC
Program counter
b15
b0
b19
b0
R2(Note)
INTB
H
L
Interrupt table register
b0
b15
b0
b15
R3(Note)
USP
User stack pointer
b15
b0
b15
b0
A0(Note) Address registers
ISP
Interrupt stack pointer
b15 b0
b15
b0
A1(Note)
SB
Static base register
b15 b0
b15
b0
FB(Note)
Frame base register
FLG
Flag register
IPL
U
I OBS Z DC
Note: These registers consist of two register banks.
Fig.BA-1 Central processing unit register
(1) Data registers (R0, R0H, R0L, R1, R1H, R1L, R2, and R3)
Data registers (R0, R1, R2, and R3) are configured with 16 bits, and are used primarily for transfer and arithmetic/logic operations. Registers R0 and R1 each can be used as separate 8-bit data registers, high-order bits as (R0H/R1H), and low-order bits as (R0L/R1L). In some instructions, registers R2 and R0, as well as R3 and R1 can use as 32bit data registers (R2R0/R3R1).
(2) Address registers (A0 and A1)
Address registers (A0 and A1) are configured with 16 bits, and have functions equivalent to those of data registers. These registers can also be u2sed for address register indirect addressing and address register relative addressing. In some instructions, registers A1 and A0 can be combined for use as a 32-bit address register (A1A0).
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z page 13 of 266
M16C/6KA Group
CPU
(3) Frame base register (FB)
Frame base register (FB) is configured with 16 bits, and is used for FB relative addressing.
(4) Program counter (PC)
Program counter (PC) is configured with 20 bits, indicating the address of an instruction to be executed.
(5) Interrupt table register (INTB)
Interrupt table register (INTB) is configured with 20 bits, indicating the start address of an interrupt vector table.
(6) Stack pointer (USP/ISP)
Stack pointer comes in two types: user stack pointer (USP) and interrupt stack pointer (ISP), each configured with 16 bits. Your desired type of stack pointer (USP or ISP) can be selected by a stack pointer select flag (U flag). This flag is located at the position of bit 7 in the flag register (FLG).
(7) Static base register (SB)
Static base register (SB) is configured with 16 bits, and is used for SB relative addressing.
(8) Flag register (FLG)
Flag register (FLG) is configured with 11 bits, each bit is used as a flag. Fig.BA-2 shows the flag register (FLG). The following explains the function of each flag: * Bit 0: Carry flag (C flag) This flag retains a carry, borrow, or shift-out bit that has occurred in the arithmetic/logic unit. * Bit 1: Debug flag (D flag) This flag enables a single-step interrupt. When this flag is "1", a single-step interrupt is generated after instruction execution. This flag is cleared to "0" when the interrupt is acknowledged. * Bit 2: Zero flag (Z flag) This flag is set to "1" when an arithmetic operation resulted in 0; otherwise, cleared to "0". * Bit 3: Sign flag (S flag) This flag is set to "1" when an arithmetic operation resulted in a negative value; otherwise, cleared to "0". * Bit 4: Register bank select flag (B flag) This flag chooses a register bank. Register bank 0 is selected when this flag is "0" ; register bank 1 is selected when this flag is "1". * Bit 5: Overflow flag (O flag) This flag is set to "1" when an arithmetic operation resulted in overflow; otherwise, cleared to "0". * Bit 6: Interrupt enable flag (I flag) This flag enables a maskable interrupt. An interrupt is disabled when this flag is "0", and is enabled when this flag is "1". This flag is cleared to "0" when the interrupt is acknowledged.
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 14 of 266
M16C/6KA Group
CPU
* Bit 7: Stack pointer select flag (U flag) Interrupt stack pointer (ISP) is selected when this flag is "0" ; user stack pointer (USP) is selected when this flag is "1". This flag is cleared to "0" when a hardware interrupt is acknowledged or an INT instruction of software interrupt No. 0 to 31 is executed. * Bits 8 to 11: Reserved area * Bits 12 to 14: Processor interrupt priority level (IPL) Processor interrupt priority level (IPL) is configured with the three bits, for specification of up to eight processor interrupt priority levels from level 0 to level 7. If a requested interrupt has priority greater than the processor interrupt priority level (IPL), the interrupt is enabled. * Bit 15: Reserved area The C, Z, S, and O flags are changed when instructions are executed. See the software manual for details.
b15
b0
IPL
U
I
OBSZDC
Flag register (FLG)
Carry flag Debug flag Zero flag Sign flag Register bank select flag Overflow flag Interrupt enable flag Stack pointer select flag Reserved area Processor interrupt priority level (CPU) Reserved area
Fig.BA-2 Flag register (FLG)
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 15 of 266
M16C/6KA Group
RESET
Reset
There are two kinds of resets; hardware and software. In both cases, operation is the same after the reset. (See "Software Reset" for details of software resets.) This section explains the hardware reset. When the supply voltage is in the range where operation is guaranteed, a reset is effected by holding the reset pin level "L" (0.2VCC max.) for at least 20 cycles. When the reset pin level is then returned to the "H" level while main clock is stable, the reset status is cancelled and program execution resumes from the address in the reset vector table. Fig.VB-1 shows the example reset circuit. Fig.VB-2 shows the reset sequence.
3.3V 3.0V VCC 0V 3.3V RESET 0.6V 0V Example when VCC = 3.3V
RESET
VCC
Fig.VB-1 Example reset circuit
XIN More than 20 cycles are needed
RESET
BCLK
24cycles
Internal clock Single chip mode Address
FFFFC16 FFFFE16
Content of reset vector
Fig.VB-2 Reset sequence
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 16 of 266
M16C/6KA Group
RESET
____________
Table VB-1 shows the statuses of the other pins while the RESET pin level is "L". Fig.VB-3 and VB-4 show the internal status of the microcomputer immediately after the reset is cancelled.
____________
Table VB-1 Pin status when RESET pin level is "L"
Status Pin name
P0 P1 P2, P3, P40 to P43 P44 P45 to P47 P50 P51 P52 P53 P54 P55 P56 P57 P6, P7, P80 to P84, P86, P87, P9, P10 P11, P12, P13, P14 P15, P16 CNVSS = VSS (M0) I/O port (floating) I/O port (floating) I/O port (floating) I/O port (floating) I/O port (floating) I/O port (floating) I/O port (floating) I/O port (floating) I/O port (floating) I/O port (floating) I/O port (floating) I/O port (floating) I/O port (floating) I/O port (floating) I/O port (floating) I/O port (floating)
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 17 of 266
M16C/6KA Group
RESET
(1) Processor mode register 0 (2) Processor mode register 1 (3) System clock control register 0 (4) System clock control register 1 (5) Address match interrupt enable register (6) Protect register (7) Watchdog timer control register (8) Address match interrupt register 0
(000416)***
0016 0
(26) Timer B5 interrupt control register (27) OBE interrupt control register (28) PS20 interrupt control register (29) PS21 interrupt control register (30) PS22 interrupt control register (31) UART1 receive interrupt control register (32) UART1 transmit interrupt control register (33) Key input 0 interrupt control register (34) Key input 1 interrupt control register (35) SI/O3 interrupt control register (36) SI/O4 interrupt control register (37) I2C0 interrupt control register (38) SCL0, SDA0 interrupt control register (39) I2C1 interrupt control register (40) SCL1, SDA1 interrupt control register (41) I2C2 interrupt control register (42) SCL2, SDA2 interrupt control register (43) INT0 interrupt control register (44) INT1 interrupt control register (45) INT2 interrupt control register (46) INT3 interrupt control register (47) INT4 interrupt control register (48) INT5 interrupt control register (49) INT6 interrupt control register (50) INT7 interrupt control register (51) INT8 interrupt control register (52) INT9 interrupt control register (53) INT10 interrupt control register (54) INT11 interrupt control register
(005416)*** (005516)*** (005616)*** (005716)*** (005816)*** (005B16)*** (005C16)*** (005F16)*** (006016)*** (006116)*** (006216)*** (006316)*** (006416)*** (006516)*** (006616)*** (006716)*** (006816)*** (006916)*** (006A16)*** (006B16)*** (006C16)*** (006D16)*** (006E16)*** (006F16)*** (007016)*** (007116)*** (007216)*** (007316)*** (007416)***
?000 ?000 ?000 ?000 ?000 ?000 ?000 ?000 ?000 ?000 ?000 ?000 ?000 ?000 ?000 ?000 ?000 00 ?000 00?000 00?000 00?000 00?000 00?000 00 ?000 00?000 00?000 00?000 00?000 00?000
(000516)*** 0 0 0 0 0
(000616)*** 0 1 0 0 1 0 0 0 (000716)*** 0 0 1 0 0 0 0 0 (000916)*** (000A16)*** 00 000
(000F16)*** 0 0 0 ? ? ? ? ? (001016)*** (001116)*** (001216)*** 0016 0016 0000 0016 0016 0000 ?000 ?000 ?000 ?000 ?000 ?000 ?000 ?000 ?000 ?000 ?000 ?000 ?000 ?000 ?000 ?000
(9) Address match interrupt register 1
(001416)*** (001516)*** (001616)***
(10) LRESET interrupt control register (11) A-D interrupt control register (12) IBF0 interrupt control register (13) IBF1 interrupt control register (14) IBF2 interrupt control register (15) IBF3 interrupt control register (16) Timer A0 interrupt control register (17) Timer A1 interrupt control register (18) Timer A2 interrupt control register (19) Timer A3 interrupt control register (20) Timer A4 interrupt control register (21) Timer B0 interrupt control register (22) Timer B1 interrupt control register (23) Timer B2 interrupt control register (24) Timer B3 interrupt control register (25) Timer B4 interrupt control register
(004116)*** (004416)*** (004516)*** (004616)*** (004716)*** (004816)*** (004A16)*** (004B16)*** (004C16)*** (004D16)*** (004E16)*** (004F16)*** (005016)*** (005116)*** (005216)*** (005316)***
x : Nothing is mapped to this bit ? : Undefined The content of other registers and RAM is undefined when the microcomputer is reset. The initial values must therefore be set.
Fig.VB-3 Device's internal status after a reset is cleared (1)
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 18 of 266
M16C/6KA Group
RESET
(55) PS20 shift register (56) PS20 status register (57) PS20 control register (58) PS21 shift register (59) PS21 status register (60) PS21 control register (61) PS22 shift register (62) PS22 status register (63) PS22 control register (64) PS2 mode register (65) Data bus buffer status register 0 (66) Data bus buffer status register 1 (67) Data bus buffer status register 2 (68) Data bus buffer status register 3 (69) Data bus buffer control register 1 (70) GateA20 control register (71) Port P11 direction register (72) Port P12 direction register (73) Port P13 direction register (74) Port P14 direction register (75) Port P15 direction register (76) Port P16 direction register (77) Port function selection register 0 (78) Port function selection register 1 (79) Port P4 input register (80) Port P7 input register (81) Pull-up control register 3 (82) Pull-up control register 4 (83) Port control register 1 (84) Port control register 2
(02A016)*** (02A116)*** (02A216)*** (02A416)*** (02A516)*** (02A616)*** (02A816)*** (02A916)*** (02AA16)*** (02AC16)*** (02C116)*** (02C316)*** (02C516)*** (02C716)*** (02C916)*** (02CA16)*** (02E216)*** (02E316)*** (02E616)*** (02E716)*** (02EA16)*** (02EB16)*** (02F816)*** (02F916)*** (02FA16)*** 0 (02FB16)*** 0 0 (02FC16)*** (02FD16)*** (02FE16)*** (02FF16)***
0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 00 0016 0016
(85) PWM control register 0 (86) PWM control register 1 (87) I2C2 address register (88) I2C2 control register 0
(030C16)*** (030D16)*** (031216)*** (031316)*** (031416)*** (031516)*** (031616)*** (031716)***
0016 0016 0016 0016 0016 1A16 3016 0016
(89) I2C2 clock control register start/stop condition control register 2C2 control register 1 (91) I (90) (92) I2C2 control register 2 (93) I2C2 status register I2C2
(031816)*** 0 0 1 0 0 0 0 (032216)*** (032316)*** (032416)*** (032516)*** (032616)*** (032716)*** 0016 0016 0016 1A16 3016 0016
(94) I2C0 address register
2 (95) I C0 control register 0
(96)
I2C0
clock control register
(97) I2C0 start/stop condition control register (98) I2C0 control register 1 (99) I2C0 control register 2
2 (100) I C0 status register
(032816)*** 0 0 1 0 0 0 0 (033216)*** (033316)*** (033416)*** (033516)*** (033616)*** (033716)*** 0016 0016 0016 1A16 3016 0016
(101)
I2C1
address register control register 0 clock control register
(102) I2C1 (103) I2C1
(104) I2C1 start/stop condition control register (105) I2C1 control register 1 (106) I2C1 control register 2
(107) I2C1 status register (108) TimerB3,4,5 count start flag (109) TimerB3 mode register (110) TimerB4 mode register
(033816)*** 0 0 1 0 0 0 0 (034016)*** 0 0 0 (035B16)*** 0 0 ? (035C16)*** 0 0 ? (035D16)*** 0 0 ? (035E16)*** (035F16)*** (036216)*** (036616)*** 0000 0000 0000 0016 0016 4016 4016
0016 0016 0016 0016
(111) TimerB5 mode register (112) Interrupt factor selection register 1 (113) Interrupt factor selection register 0 (114) SI/O3 control register (115) SI/O4 control register
x : Nothing is mapped to this bit ? : Undefined The content of other registers and RAM is undefined when the microcomputer is reset. The initial values must therefore be set.
Fig.VB-4 Device's internal status after a reset is cleared (2)
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 19 of 266
M16C/6KA Group
RESET
(116) Count start flag (117) One-shot start flag (118) Trigger select flag (119) Up-down flag (120) Timer A0 mode register (121) Timer A1 mode register (122) Timer A2 mode register (123) Timer A3 mode register (124) Timer A4 mode register (125) Timer B0 mode register (126) Timer B1 mode register (127) Timer B2 mode register (128) UART1 transmit/receive mode register (129) UART1 transmit/receive control register 0 (130) UART1 transmit/receive control register 1 (131) UART transmit/receive control register 2 (132) Flash memory recognition register (Note1) (133) Flash memory control register1 (Note1) (134) Flash memory control register0 (Note1) (135) A-D control register 2 (136) A-D control register 0 (137) A-D control register 1
(038016)*** (038216)*** 0 0 (038316)*** (038416)*** (039616)*** (039716)*** (039816)*** (039916)*** (039A16)*** (039B16)*** 0 0 ? (039C16)*** 0 0 ? (039D16)*** 0 0 ? (03A816)***
0016 00000 0016 0016 0016 0016 0016 0016 0016 0000 0000 0000 0016
(138) Port P0 direction register (139) Port P1 direction register (140) Port P2 direction register (141) Port P3 direction register (142) Port P4 direction register (143) Port P5 direction register (144) Port P6 direction register (145) Port P7 direction register (146) Port P8 direction register (147) Port P9 direction register (148) Port P10 direction register (149) Pull-up control register 0 (150) Pull-up control register 1 (151) Pull-up control register 2 (152) Port control register 0 (153) Data registers (R0/R1/R2/R3) (154) Address registers (A0/A1) (155) Frame base register (FB) (156) Interrupt table register (INTB) (157) User stack pointer (USP) (158) Interrupt stack pointer (ISP) (159) Static base register (SB) (160) Flag register (FLG)
(03E216)*** (03E316)*** (03E616)*** (03E716)*** (03EA16)*** (03EB16)*** (03EE16)*** (03EF16)*** (03F216)*** 0 0 (03F316)*** (03F616)*** (03FC16)*** (03FD16)*** (03FE16)*** (03FF16)***
0016 0016 0016 0016 0016 0016 0016 0016 00000 0016 0016 0016 0016 0016 0016 000016 000016 000016 0000016 000016 000016 000016 000016
(03AC16)*** 0 0 0 0 1 0 0 0 (03AD16)*** 0 0 0 0 0 0 1 0 (03B016)*** (03B416)*** (03B516)*** 0 0 0 0000000 11 0
(03B716)*** 0 0 0 0 0 0 0 1 (03D416)*** 0 0 0 1 0 0 0 0 (03D616)*** 0 0 0 0 0 ? ? ? (03D716)*** 0016
x : Nothing is mapped to this bit ? : Undefined The content of other registers and RAM is undefined when the microcomputer is reset. The initial values must therefore be set. (Note1) This register exists only in the flash memory version.
Fig.VB-5 Device's internal status after a reset is cleared (3)
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 20 of 266
M16C/6KA Group
RESET
(161) Serial interrupt control register 0 (162) Serial interrupt control register 1 (163) IRQ request register 0 (164) IRQ request register 1 (165) IRQ request register 2 (166) IRQ request register 3 (167) IRQ request register 4 (168) Serial interrupt control register 2 (169) LPC1 address register L (170) LPC1 address register H (171) LPC2 address register L (172) LPC2 address register H (173) LPC3 address register L (174) LPC3 address register H (175) LPC control register (176) Port function selection register 2 (177) Pull-up resistor control register 5 (178) Pull-up resistor control register 6 (179) Key input interrupt 1 enable register (180) Key input interrupt 1 edge selection register (181) P14 event register (182) Port control register 3
(02B016)*** (02B116)*** (02B216)*** (02B316)*** (02B416)*** (02B516)*** (02B616)*** (02B716)*** (02D016)*** (02D116)*** (02D216)*** (02D316)*** (02D416)*** (02D516)*** (02D616)*** (02F116)*** (02F216)*** (02F316)*** (02F416)*** (02F516)*** (02F616)*** (02F716)***
0016 0016 0016 0016 0016 0016 0016 1016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016
The content of other registers and RAM is undefined when the microcomputer is reset. The initial values must therefore be set.
Fig.VB-6 Device's internal status after a reset is cleared (4)
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 21 of 266
M16C/6KA Group
SFR
000016 000116 000216 000316 000416 000516 000616 000716 000816 000916 000A16 000B16 000C16 000D16 000E16 000F16 001016 001116 001216 001316 001416 001516 001616 001716 001816 001916 001A16 001B16 001C16 001D16 001E16 001F16 002016 002116 002216 002316 002416 002516 002616 002716 002816 002916 002A16 002B16 002C16 002D16 002E16 002F16 003016 003116 003216 003316 003416 003516 003616 003716 003816 003916 003A16 003B16 003C16 003D16 003E16 003F16
004016 004116 004216 004316
LRESET interrupt control register (LRSTIC)
Processor mode register 0 (PM0) Processor mode register 1(PM1) System clock control register 0 (CM0) System clock control register 1 (CM1) Address match interrupt enable register (AIER) Protect register (PRCR)
004416 004516 004616 004716 004816 004916 004A16 004B16 004C16 004D16
A-D interrupt control register (A-DIC) IBF0 interrupt control register (IBF0IC) IBF1 interrupt control register (IBF1IC) IBF2 interrupt control register (IBF2IC) IBF3 interrupt control register (IBF3IC) Timer A0 interrupt control register (TA0IC) Timer A1 interrupt control register (TA1IC) Timer A2 interrupt control register (TA2IC) Timer A3 interrupt control register (TA3IC) Timer A4 interrupt control register (TA4IC) Timer B0 interrupt control register (TB0IC) Timer B1 interrupt control register (TB1IC) Timer B2 interrupt control register (TB2IC) Timer B3 interrupt control register (TB3IC) Timer B4 interrupt control register (TB4IC) Timer B5 interrupt control register (TB5IC) OBE interrupt control register (OBEIC) PS20 interrupt control register (PS20IC) PS21 interrupt control register (PS21IC) PS22 interrupt control register (PS22IC)
Watchdog timer start register (WDTS) Watchdog timer control register (WDC) Address match interrupt register 0 (RMAD0)
004E16 004F16 005016 005116 005216 005316 005416
Address match interrupt register 1 (RMAD1)
005516 005616 005716 005816 005916 005A16 005B16 005C16 005D16 005E16 005F16 006016 006116 006216 006316 006416 006516 006616 006716 006816 006916 006A16 006B16 006C16 006D16 006E16 006F16 007016 007116 007216 007316 007416
UART1 receive interrupt control register (S1RIC) UART1 transmit interrupt control register (S1TIC)
Key input interrupt 0 control register (KUP0IC) Key input interrupt 1 control register (KUP1IC) SI/O3 interrupt control register (S3IC) SI/O4 interrupt control register (S4IC) I2C0 interrupt control register (IIC0IC)
SCL0,SDA0 interrupt control register (SCLDA0IC)
I2C1 interrupt control register (IIC1IC)
SCL1,SDA1 interrupt control register (SCLDA1IC)
I2C2 interrupt control register (IIC2IC)
SCL2,SDA2 interrupt control register (SCLDA2IC)
INT0 interrupt control register (INT0IC) INT1 interrupt control register (INT1IC) INT2 interrupt control register (INT2IC) INT3 interrupt control register (INT3IC) INT4 interrupt control register (INT4IC) INT5 interrupt control register (INT5IC) INT6 interrupt control register (INT6IC) INT7 interrupt control register (INT7IC) INT8 interrupt control register (INT8IC) INT9 interrupt control register (INT9IC) INT10 interrupt control register (INT10IC) INT11 interrupt control register (INT11IC)
027E16 027F16
Note 1: The areas that nothing are allocated in SFR are reserved. Read and Write to the areas are inhibited.
Fig.CA-2 Location of peripheral unit control registers (1)
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z page 22 of 266
M16C/6KA Group
SFR
028016 028116 028216 028316 028416 028516 028616 028716 028816 028916 028A16 028B16 028C16 028D16 028E16 028F16 029016 029116 029216 029316 029416 029516 029616 029716 029816 029916 029A16 029B16 029C16 029D16 029E16 029F16 02A016 02A116 02A216 02A316 02A416 02A516 02A616 02A716 02A816 02A916 02AA16 02AB16 02AC16 02AD16 02AE16 02AF16 02B016 02B116 02B216 02B316 02B416 02B516 02B616 02B716 02B816 02B916 02BA16 02BB16 02BC16 02BD16 02BE16 02BF16
02C016 02C116 02C216 02C316 02C416 02C516 02C616 02C716 02C816 02C916 02CA16 02CB16 02CC16 02CD16 02CE16 02CF16 02D016 02D116 02D216 02D316 02D416 02D516 02D616 02D716 02D816 02D916 02DA16 02DB16 02DC16 02DD16 02DE16 02DF16
Data bus buffer register0 (DBB0) Data bus buffer status register0 (DBBSTS0) Data bus buffer register1 (DBB1) Data bus buffer status register1 (DBBSTS1) Data bus buffer register2 (DBB2) Data bus buffer status register2 (DBBSTS2) Data bus buffer register3 (DBB3) Data bus buffer status register3 (DBBSTS3) Data bus buffer control register1 (DBBCON1) Gate A20 control register (GA20CON)
LPC1 address registerL (LPC1ADL) LPC1 address registerH (LPC1ADH) LPC2 address registerL (LPC2ADL) LPC2 address registerH (LPC2ADH) LPC3 address registerL (LPC3ADL) LPC3 address registerH (LPC3ADH) LPC control register (LPCCON)
PS20 shift register (PS20SR) PS20 status register (PS20STS) PS20 control register (PS20CON) PS21 shift register (PS21SR) PS21 status register (PS21STS) PS21 control register (PS21CON) PS22 shift register (PS22SR) PS22 status register (PS22STS) PS22 control register (PS22CON) PS2 mode register (PS2MOD)
02E016 02E116 02E216 02E316 02E416 02E516 02E616 02E716 02E816 02E916 02EA16 02EB16 02EC16 02ED16 02EE16 02EF16
Port P11 (P11) Port P12 (P12) Port P11 direction register (PD11) Port P12 direction register (PD12) Port P13 (P13) Port P14 (P14) Port P13 direction register (PD13) Port P14 direction register (PD14) Port P15 (P15) Port P16 (P16) Port P15 direction register (PD15) Port P16 direction register (PD16)
Serial Interrupt control register 0 (SERCON0) Serial Interrupt control register 1 (SERCON1) IRQ request register 0 (IRQ0) IRQ request register 1 (IRQ1) IRQ request register 2 (IRQ2) IRQ request register 3 (IRQ3) IRQ request register 4 (IRQ4) Serial Interrupt control register 2 (SERCON2)
02F016 02F116 02F216 02F316 02F416 02F516 02F616 02F716 02F816 02F916 02FA16 02FB16 02FC16 02FD16 02FE16 02FF16
Port function selection register 2 (PSL2) Pull-up resistor control register 5 (PUR5) Pull-up resistor control register 6 (PUR6) Key input interrupt 1 enable register (KIN1EN)
Key input interrupt 1 edge selection regiter (KINSEL)
P14 event register (P14EV) Port control register3 (PCR3) Port function selection register0 (PSL0) Port function selection register1 (PSL1) Port P4 input register (P4PIN) Port P7 input register (P7PIN) Pull-up control register3 (PUR3) Pull-up control register4 (PUR4) Port control register1 (PCR1) Port control register2 (PCR2)
Note 1: The areas that nothing are allocated in SFR are reserved. Read and Write to the areas are inhibited.
Fig.CA-3 Location of peripheral unit control registers (2)
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z page 23 of 266
M16C/6KA Group
SFR
030016 030116 030216 030316 030416 030516 030616 030716 030816 030916 030A16 030B16 030C16 030D16 030E16 030F16 031016 031116 031216 031316 031416 031516 031616 031716 031816 031916 031A16 031B16 031C16 031D16 031E16 031F16 032016 032116 032216 032316 032416 032516 032616 032716 032816 032916 032A16 032B16 032C16 032D16 032E16 032F16 033016 033116 033216 033316 033416 033516 033616 033716 033816 033916 033A16 033B16 033C16 033D16 033E16 033F16
PWM0 prescaler (PREPWM0) PWM0 register (PWM0) PWM1 prescaler (PREPWM1) PWM1 register (PWM1) PWM2 prescaler (PREPWM2) PWM2 register (PWM2) PWM3 prescaler (PREPWM3) PWM3 register (PWM3) PWM4 prescaler (PREPWM4) PWM4 register (PWM4) PWM5 prescaler (PREPWM5) PWM5 register (PWM5) PWM control register 0 (PWMCON0) PWM control register 1 (PWMCON1)
034016 034116 034216 034316 034416 034516 034616 034716 034816 034916 034A16 034B16 034C16 034D16 034E16 034F16
TimerB3,4,5 count start flag (TBSR)
I2C2 data shift register (S02) address register (S0D2) I I2C2 control register 0 (S1D2) I2C2 clock control register (S22) I2C2 start/stop condition control register (S2D2) I2C2 control register 1 (S3D2) I2C2 control register 2 (S4D2) I2C2 status register (S12)
2C2
035016 035116 035216 035316 035416 035516 035616 035716 035816 035916 035A16 035B16 035C16 035D16 035E16 035F16
TimerB3 register (TB3) TimerB4 register (TB4) TimerB5 register (TB5)
I2C0 data shift register (S00) I2C0 address register (S0D0) I2C0 control register0 (S1D0) I2C0 clock control register (S20) I2C0 start/stop condition control register (S2D0) I2C0 control register1 (S3D0) I2C0 control register2 (S4D0) I2C0 status register (S10)
036016 036116 036216 036316 036416 036516 036616 036716 036816 036916 036A16 036B16 036C16 036D16 036E16 036F16
TimerB3 mode register (TB3MR) TimerB4 mode register (TB4MR) TimerB5 mode register (TB5MR) Interrupt event select register 1 (IFSR1) Interrupt event select register 0 (IFSR0) SI/O3 transmit/receive register (S3TRR) SI/O3 control register (S3C) SI/O3 communication speed register (S3BRG) SI/O4 transmit/receive register (S4TRR) SI/O4 control register (S4C) SI/O4 communication speed register (S4BRG)
I2C1 data shift register (S01) I2C1 address register (S0D1) I2C1 control register0 (S1D1) I2C1 clock control register (S21) I2C1 start/stop condition control register (S2D1) I2C1 control register1 (S3D1) I2C1 control register2 (S4D1) I2C1 status register (S11)
037016 037116 037216 037316 037416 037516 037616 037716 037816 037916 037A16 037B16 037C16 037D16 037E16 037F16
Note 1: The areas that nothing are allocated in SFR are reserved. Read and Write to the areas are inhibited.
Fig.CA-4 Location of peripheral unit control registers (3)
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z page 24 of 266
M16C/6KA Group
SFR
038016 038116 038216 038316 038416 038516 038616 038716 038816 038916 038A16 038B16 038C16 038D16 038E16 038F16 039016 039116 039216 039316 039416 039516 039616 039716 039816 039916 039A16 039B16 039C16 039D16 039E16 039F16 03A016 03A116 03A216 03A316 03A416 03A516 03A616 03A716 03A816 03A916 03AA16 03AB16 03AC16 03AD16 03AE16 03AF16 03B016 03B116 03B216 03B316 03B416 03B516 03B616 03B716 03B816 03B916 03BA16 03BB16 03BC16 03BD16 03BE16 03BF16
Count start flag (TABSR) One-shot start flag (ONSF) Trigger select register (TRGSR) Up-down flag (UDF) TimerA0 (TA0) TimerA1 (TA1) TimerA2 (TA2) TimerA3 (TA3) TimerA4 (TA4) TimerB0 (TB0) TimerB1 (TB1) TimerB2 (TB2) TimerA0 mode register (TA0MR) TimerA1 mode register (TA1MR) TimerA2 mode register (TA2MR) TimerA3 mode register (TA3MR) TimerA4 mode register (TA4MR) TimerB0 mode register (TB0MR) TimerB1 mode register (TB1MR) TimerB2 mode register (TB2MR)
03C016 03C116 03C216 03C316 03C416 03C516 03C616 03C716 03C816 03C916 03CA16 03CB16 03CC16 03CD16 03CE16 03CF16 03D016 03D116 03D216 03D316 03D416 03D516 03D616 03D716 03D816 03D916 03DA16 03DB16 03DC16 03DD16 03DE16 03DF16 03E016 03E116 03E216 03E316 03E416 03E516 03E616 03E716
A-D register0 (AD0) A-D register1 (AD1) A-D register2 (AD2) A-D register3 (AD3) A-D register4 (AD4) A-D register5 (AD5) A-D register6 (AD6) A-D register7 (AD7)
A-D control register2 (ADCON2) A-D control register0 (ADCON0) A-D control register1 (ADCON1)
UART1 transmit/receive mode register (U1MR) UART1 communication speed register (U1BRG) UART1 tranmit buffer register (U1TB) UART1 transmit/receive control register0 (U1C0) UART1 transmit/receive control register1 (U1C1) UART1 receive buffer register (U1RB) UART transmit/receive control register2 (UCON)
03E816 03E916 03EA16 03EB16 03EC16 03ED16 03EE16 03EF16 03F016 03F116 03F216 03F316
Flash memory identification register (FTR) Flash memory control register1 (FMR1) Flash memory control register0 (FMR0)
03F416 03F516 03F616 03F716 03F816 03F916 03FA16 03FB16 03FC16 03FD16 03FE16 03FF16
Port P0 (P0) Port P1 (P1) Port P0 direction register (P0D) Port P1 direction register (P1D) Port P2 (P2) Port P3 (P3) Port P2 direction register (P2D) Port P3 direction register (P3D) Port P4 (P4) Port P5 (P5) Port P4 direction register (P4D) Port P5 direction register (P5D) Port P6 (P6) Port P7 (P7) Port P6 direction register (P6D) Port P7 direction register (P7D) Port P8 (P8) Port P9 (P9) Port P8 direction register (P8D) Port P9 direction register (P9D) Port P10 (P10) Port P10 direction register (P10D)
Pull-up control register0 (PUR0) Pull-up control register1 (PUR1) Pull-up control register2 (PUR2) Port control register0 (PCR0)
Note 1: The areas that nothing are allocated in SFR are reserved. Read and Write to the areas are inhibited.
Fig.CA-5 Location of peripheral unit control registers (4)
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z page 25 of 266
M16C/6KA Group
Software Reset
Software Reset
Writing "1" to bit 3 of the processor mode register 0 (address 000416) applies a (software) reset to the microcomputer. A software reset has almost the same effect as a hardware reset. The contents of internal RAM are retained.
Processor Mode (1) Types of Processor Mode
The single-chip mode is supported in processor mode. * Single-chip mode In single-chip mode, only internal memory space (SFR, internal RAM, and internal ROM) can be accessed. Ports P0 to P16 can be used as programmable I/O ports or as I/O ports for the internal peripheral functions. Fig. BG-1 shows the structure of processor mode register 0 and processor mode register 1.
Processor mode register 0 (Note 1)
b7 b6 b5 b4 b3 b2 b1 b0
0000
0
Symbol PM0
Address 000416
When reset 0016 (Note 2)
Bit symbol
PM00 PM01
Bit name
Processor mode bit
b1 b0
Function
0 0: Single-chip mode 0 1: Inhibited 1 0: Inhibited 1 1: Inhibited
RW
Reserved bit
PM03
Must always be set to "0"
The device is reset when this bit is set to "1". The value of this bit is "0" when read.
Software reset bit
Reserved bit
Must always be set to "0"
Note 1: Set bit 1 of the protect register (address 000A16) to "1" when writing new values to this register.
Processor mode register 1 (Note 1)
b7 b6 b5 b4 b3 b2 b1 b0
000
0
0
Symbol PM1
Address 000516
When reset 00000XX02
Bit symbol
Reserved bit
Bit name
Function
Must always be set to "0"
RW
Nothing is assigned. In an attempt to write to these bits, write "0". The value, if read, turns out to be indeterminate. Reserved bit PM17 Wait bit Must always be set to "0" 0 : No wait state 1 : Wait state inserted
Note 1: Set bit 1 of the protect register (address 000A16) to "1" when writing new values to this register.
Fig.BG-1 Processor mode register 0 and 1
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 26 of 266
M16C/6KA Group
Bus control
Bus control (1) Software wait
A software wait can be inserted by setting the wait bit (bit 7) of the processor mode register 1 (address 000516) (Note) . A software wait is inserted in the internal ROM/RAM area by setting the wait bit of the processor mode register 1. When set to "0", each bus cycle is executed in one BCLK cycle. When set to "1", each bus cycle is executed in 2 BCLK cycles. After the microcomputer has been reset, this bit defaults to "0". Set this bit after referring to the recommended operating conditions (main clock input oscillation frequency) of the electric characteristics. The SFR area is always accessed in two BCLK cycles regardless of the setting of these control bits. Table.EF-1 shows the software wait and bus cycles. Fig.EF-1 shows example bus timing when using software waits. Note: Before attempting to change the contents of the processor mode register 1, set bit 1 of the protect register (address 000A16) to "1".
Table.EF-1 Software waits and bus cycles
Area SFR Internal ROM/RAM Wait bit Invalid 0 1 Bus cycle 2 BCLK cycles 1 BCLK cycle 2 BCLK cycles
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 27 of 266
M16C/6KA Group
Bus control
No wait
Bus cycle
(Note 1)
Bus cycle
(Note 1)
BCLK Write signal Read signal
Data bus Address bus Chip select
Output
Input
Address
Address
With wait
Bus cycle
(Note 1)
Bus cycle
(Note 1)
BCLK Write signal Read signal
Output Input
Data bus Address bus Chip select
Address
Address
Note 1: This timing sample shows the lenth of bus cycle. It is possible that the read cyles, write cycle comes after this cycle in succession.
Fig.EF-1 Typical bus timings using software wait
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 28 of 266
M16C/6KA Group
Clock Generating Circuit
Clock Generating Circuit
The clock generating circuit contains two oscillator circuits that supply the operating clock sources to the CPU and internal peripheral units. Table.WA-1 Main clock generating circuits Use of clock Main clock generating circuit * CPU's operating clock source * Internal peripheral units' operating clock source Ceramic oscillator XIN, XOUT Available Oscillating Externally derived clock can be input
Usable oscillator Pins to connect oscillator Oscillation stop/restart function Oscillator status immediately after reset Other
Example of oscillator circuit
Fig.WA-1 shows some examples of the main clock circuit, one using an oscillator connected to the circuit, and the other one using an externally derived clock for input. Circuit constants in Fig.WA-1 vary with oscillator used. Use the values recommended by the manufacturer of your oscillator.
Microcomputer
(Built-in feedback resistor)
Microcomputer
(Built-in feedback resistor)
XIN
XOUT (Note) Rd
XIN
XOUT Open
Externally derived clock CIN COUT Vcc Vss
Note: Insert a damping resistor if required. The resistance will vary depending on the oscillator and the oscillation drive capacity setting. Use the value recommended by the maker of the oscillator. When the oscillation drive capacity is set to low, check that oscillation is stable. Apply the feedback register between XIN and XOUT if required by oscillator maker.
Fig.WA-1 Examples of main clock
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 29 of 266
M16C/6KA Group
Clock Generating Circuit
Clock Control
Fig.WA-2 shows the block diagram of the clock generating circuit.
f1 f1SIO2 fAD f8 CM10 "1" Write signal f32 XIN R a RESET Software reset NMI Interrupt request level judgment output WAIT instruction Main clock CM02 XOUT b c d BCLK Divider f8SIO2 f32SIO2 SQ
SQ R
b a
1/2 1/2 1/2 1/2 1/2
c
CM06=0 CM17,CM16=11 CM06=1 CM06=0 CM17,CM16=10
d
CM06=0 CM17,CM16=01 CM06=0 CM17,CM16=00 CM0i : Bit i at address 000616 CM1i : Bit i at address 000716
Details of divider
Fig.WA-2 Clock generating circuit
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 30 of 266
M16C/6KA Group
Clock Generating Circuit
The following paragraphs describes the clocks generated by the clock generating circuit.
(1) Main clock
The main clock is generated by the main clock oscillation circuit. After a reset, the clock is divided by 8 to the BCLK. The clock can be stopped using the main clock stop bit (bit 5 at address 000616). After the oscillation of the main clock oscillation circuit has stabilized, the drive capacity of the main clock oscillation circuit can be reduced using the XIN-XOUT drive capacity select bit (bit 5 at address 000716). Reducing the drive capacity of the main clock oscillation circuit reduces the power dissipation. This bit defaults to "1" when shifting from high speed mode or mid-speed mode to stop mode and after a reset.
(2) BCLK
The BCLK is the clock that drives the CPU, and is either the main clock or is derived by dividing the main clock by 2, 4, 8, or 16. The BCLK is derived by dividing the main clock by 8 after a reset. When shifting from high speed mode or mid-speed mode to stop mode, the main clock division select bit (bit 6 at 000616) is set to "1".
(3) Peripheral function clock
f1, f8, f32, f1SIO2, f8SIO2, f32SIO2, fAD The clock for the peripheral devices is derived from the main clock or by dividing it by 8 or 32. The peripheral function clock is stopped by stopping the main clock or by setting the WAIT peripheral function clock stop bit (bit 2 at 000616) to "1" and then executing a WAIT instruction.
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 31 of 266
M16C/6KA Group
Clock Generating Circuit
Fig.WA-3 shows the system clock control registers 0 and 1.
System clock control register 0
b7 b6 b5 b4 b3 b2 b1 b0
(Note 1)
0
0
0
1
Symbol CM0 Bit symbol
CM00 CM01
Address 000616 Bit name
Clock output function select bit
When reset 4816 Function
b1 b0
RW
0 0 : I/O port P57 0 1 : Inhibited 1 0 : f8 output 1 1 : f32 output
0 :Do not stop peripheral clock in wait mode 1 :Stop peripheral clock in wait mode
CM02
WAIT peripheral function clock stop bit
Reserved bit Reserved bit CM06 Main clock division select bit 0 (Note 2)
Always set to "1" Always set to "0" 0 : CM16 and CM17 valid 1 : Division by 8 mode Always set to "0"
Reserved bit
Note 1 : Set bit 0 of the protect register (address 000A16) to "1" before writing to this register. Note 2 : The bit is set to "1" when shifting from high speed mode or mid speed mode to stop mode and after reset.
System clock control register 1 (Note 1)
b7 b6 b5 b4 b3 b2 b1 b0
0
0
0
0
Symbol CM1 Bit symbol
CM10
Address 000716 Bit name
All clock stop control bit (Note 4)
When reset 2016 Function
0 : Clock on 1 : All clocks off (stop mode) Always set to "0" Always set to "0" Always set to "0" Always set to "0" 0 : LOW 1 : HIGH
b7 b6
RW
Reserved bit Reserved bit Reserved bit Reserved bit CM15 XIN-XOUT drive capacity select bit (Note 2) Main clock division select bit 1 (Note 3)
CM16 CM17
0 0 : No division mode 0 1 : Division by 2 mode 1 0 : Division by 4 mode 1 1 : Division by 16 mode
Note 1: Set bit 0 of the protect register (address 000A16) to "1" before writing to this register. Note 2: The bit is set to "1" when shifting from high speed mode or mid speed mode to stop mode and after reset. Note 3: Can be selected when bit 6 of the system clock control register 0 (address 000616) is "0". If "1", division mode is fixed at 8. Note 4: If this bit is set to "1", XOUT turns "H", and the built-in feedback resistor turns null.
Fig.WA-3 System clock control registers 0 and 1
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z page 32 of 266
M16C/6KA Group
Clock Generating Circuit
Clock Output
In single-chip mode, the clock output function select bits (bits 0 and 1 at address 000616) enable f8, f32 to be output from the P57/CLKOUT pin. When the WAIT peripheral function clock stop bit (bit 2 at address 000616) is set to "1", the output of f8 and f32 stops when a WAIT instruction is executed. By setting the f1 output function selection bits (bits 0 and 1 at address 02F116), the same frequency clock with f(XIN) can be output from P110 and P111.
Stop Mode
Writing "1" to the all-clock stop control bit (bit 0 at address 000716) stops all oscillation and the microcomputer enters stop mode. In stop mode, the content of the internal RAM is retained provided that VCC remains above 2V. The oscillation , BCLK, f1 to f32, f1SIO2 to f32SIO2, and fAD stop in stop mode, peripheral functions such as the A-D converter and watchdog timer do not function. However, timer A and timer B operate provided that the event counter mode is set to an external pulse, and UART1, SIO3,4 functions provided an external clock is selected. Table.WA-2 shows the status of the ports in stop mode. Stop mode is cancelled by a hardware reset or interrupt. If an interrupt is to be used to cancel stop mode, that interrupt must first have been enabled. After the restoration by interrupt, the corresponding interrupt routine will be processed. When shifting from high speed mode or mid-speed mode to stop mode, the main clock division select bit 0 (bit 6 at 000616) is set to "1". Table.WA-2 Port status during stop mode Pin Port CLKOUT When f8, f32 selected Single-chip mode Retains status before stop mode Retains status before stop mode
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 33 of 266
M16C/6KA Group
Wait Mode
Wait Mode
When a WAIT instruction is executed, the BCLK stops and the microcomputer enters the wait mode. In this mode, oscillation continues but the BCLK and watchdog timer stop. Writing "1" to the WAIT peripheral function clock stop bit and executing a WAIT instruction stops the clock being supplied to the internal peripheral functions, allowing power dissipation to be reduced. Table.WA-3 shows the status of the ports in wait mode. Wait mode is cancelled by a hardware reset or interrupt. If an interrupt is used to cancel wait mode, the microcomputer restarts from interrupt routine using as BCLK, the clock that had been selected when the WAIT instruction was executed.
Table.WA-3 Port status during wait mode Pin Single-chip mode CLKOUT When f8, f32 selected Does not stop when the WAIT peripheral function clock stop bit is "0". When the WAIT peripheral function clock stop bit is "1", the Port status immediately prior to entering wait mode is maintained. maintained the status immediately prior to entering wait mode
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 34 of 266
M16C/6KA Group
Status Transition Of BCLK
Status Transition Of BCLK
Power dissipation can be reduced and low-voltage operation achieved by changing the count source for BCLK. Table.WA-4 shows the operating modes corresponding to the settings of system clock control registers 0 and 1. After a reset, operation defaults to division by 8 mode. When shifting from high speed mode or mid-speed mode to stop mode, and after a reset main clock division select bit 0 (bit 6 at address 000616) is set to "1".
(1) Division by 2 mode
The main clock is divided by 2 to obtain the BCLK.
(2) Division by 4 mode
The main clock is divided by 4 to obtain the BCLK.
(3) Division by 8 mode
The main clock is divided by 8 to obtain the BCLK. After reset, it works in this mode. Note that oscillation of the main clock must have stabilized before transferring from this mode to No-division, Division by 2 and Division by 4 mode.
(4) Division by 16 mode
The main clock is divided by 16 to obtain the BCLK.
(5) No-division mode
The main clock is used as the BCLK.
Table.WA-4 Operating modes dictated by settings of system clock control registers 0 and 1 CM17 0 1 Invalid 1 0 CM16 1 0 Invalid 1 0 CM06 0 0 1 0 0 Operating mode of BCLK Division by 2 mode Division by 4 mode Division by 8 mode Division by 16 mode No-division mode
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 35 of 266
M16C/6KA Group
Power control
Power control
The following is a description of the power control modes:
Modes
Power control is available in three modes. (1) Normal operation mode * High-speed mode Divide-by-1 frequency of the main clock becomes the BCLK. The CPU operates with the internal clock selected. Each peripheral function operates according to its assigned clock. * Medium-speed mode Divide-by-2, divide-by-4, divide-by-8, or divide-by-16 frequency of the main clock becomes the BCLK. The CPU operates according to the internal clock selected. Each peripheral function operates according to its assigned clock. (2) Wait mode The CPU operation is stopped. The oscillators do not stop. (3) Stop mode All oscillators stop. The CPU and all built-in peripheral functions stop. This mode, among the three modes listed here, is the most effective in decreasing power consumption. Fig.WA-4 is the state transition diagram of (1) to (3).
Transition of stop mode, wait mode
Reset
All oscillators stop
CM10 = "1"
WAIT command Medium-speed mode (Divided-by-8 mode) Interrupt WAIT command High-speed/mediumspeed mode Interrupt
CPU operation stop
Stop mode
Interrupt All oscillators stop Interrupt
CM10 = "1"
Wait mode
CPU operation stop
Stop mode
Wait mode
Normal mode
Fig.WA-4 State transition diagram of Power control mode
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 36 of 266
M16C/6KA Group
Protection
Protection
The protection function is provided so that the values in important registers cannot be changed in the event that the program runs out of control. Fig.WA-5 shows the protect register. The values in the processor mode register 0 (address 000416), processor mode register 1 (address 000516), system clock control register 0 (address 000616), system clock control register 1 (address 000716), can only be changed when the respective bit in the protect register is set to "1".
Protect register
b7 b6 b5 b4 b3 b2 b1 b0
0
Symbol PRCR Bit symbol
PRC0
Address 000A16 Bit name
When reset XXXXX0002 Function RW
Enables writing to system clock 0 : Write-inhibited control registers 0 and 1 (addresses 1 : Write-enabled 000616 and 000716) Enables writing to processor mode 0 : Write-inhibited registers 0 and 1 (addresses 000416 1 : Write-enabled and 000516) Must be "0"
PRC1
Reserved bit
Nothing is assigned. In an attempt to write to these bits, write "0". The value, if read, turns out to be indeterminate.
Fig.WA-5 Protect register
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 37 of 266
M16C/6KA Group
Interrupt
Overview of Interrupt Type of Interrupts
Fig.DD-1 lists the types of interrupts.
Software
Interrupt
Special
Hardware
Peripheral I/O (Note)
Note: Peripheral I/O interrupts are generated by the peripheral functions built into the microcomputer system. Fig.DD-1 Classification of interrupts * Maskable interrupt : An interrupt which can be enabled (disabled) by the interrupt enable flag (I flag) or whose interrupt priority can be changed by priority level. * Non-maskable interrupt : An interrupt which cannot be enabled (disabled) by the interrupt enable flag (I flag) or whose interrupt priority cannot be changed by priority level.
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 38 of 266

Undefined instruction (UND instruction) Overflow (INTO instruction) BRK instruction INT instruction Reset NMI ________ DBC Watchdog timer Single step Address matched
_______

M16C/6KA Group
Interrupt
Software Interrupts
A software interrupt occurs when executing certain instructions. Software interrupts are non-maskable interrupts. * Undefined instruction interrupt An undefined instruction interrupt occurs when executing the UND instruction. * Overflow interrupt An overflow interrupt occurs when executing the INTO instruction with the overflow flag (O flag) set to "1". The following are instructions whose O flag changes by arithmetic: ABS, ADC, ADCF, ADD, CMP, DIV, DIVU, DIVX, NEG, RMPA, SBB, SHA, SUB * BRK interrupt A BRK interrupt occurs when executing the BRK instruction. * INT interrupt An INT interrupt occurs when assigning one of software interrupt numbers 0 through 63 and executing the INT instruction. Software interrupt numbers 0 through 52 are assigned to peripheral I/O interrupts, so executing the INT instruction allows executing the same interrupt routine that a peripheral I/O interrupt does. The stack pointer (SP) used for the INT interrupt is dependent on which software interrupt number is involved. So far as software interrupt numbers 0 through 31 are concerned, the microcomputer saves the stack pointer assignment flag (U flag) when it accepts an interrupt request. If change the U flag to "0" and select the interrupt stack pointer (ISP), and then execute an interrupt sequence. When returning from the interrupt routine, the U flag is returned to the state it was before the acceptance of interrupt request. So far as software numbers 32 through 63 are concerned, the stack pointer does not make a shift.
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 39 of 266
M16C/6KA Group
Interrupt
Hardware Interrupts
Hardware interrupts are classified into two types -- special interrupts and peripheral I/O interrupts. (1) Special interrupts Special interrupts are non-maskable interrupts. * Reset ____________ Reset occurs if an "L" is input to the RESET pin. _______ * NMI interrupt _______ _______ An NMI interrupt occurs if an "L" is input to the NMI pin. ________ * DBC interrupt This interrupt is exclusively for the debugger, do not use it in other circumstances. * Watchdog timer interrupt Generated by the watchdog timer. * Single-step interrupt This interrupt is exclusively for the debugger, do not use it in other circumstances. With the debug flag (D flag) set to "1", a single-step interrupt occurs after one instruction is executed. * Address match interrupt An address match interrupt occurs immediately before the instruction held in the address indicated by the address match interrupt register is executed with the address match interrupt enable bit set to "1". If an address other than the first address of the instruction in the address match interrupt register is set, no address match interrupt occurs. (2) Peripheral I/O interrupts A peripheral I/O interrupt is generated by one of built-in peripheral functions. Built-in peripheral functions are dependent on classes of products, so the interrupt factors are also dependent on classes of products. The interrupt vector table is the same as the one for software interrupt numbers 0 through 52 the INT instruction uses. Peripheral I/O interrupts are maskable interrupts. 1)Key-input interrupt 0 ___ A key-input interrupt occurs if an "L" is input to the KI pin. 2)Key-input interrupt 1 ___ A key-input interrupt occurs if an "L" or "H" is input to the KI pin. 3)A-D conversion interrupt This is an interrupt that the A-D converter generates. 4)UART1, SI/O3 and SI/O4 transmission interrupt These are interrupts that the serial I/O transmission generates. 5)UART1, SI/O3 and SI/O4 reception interrupt These are interrupts that the serial I/O reception generates. 6)Timer A0 interrupt through timer A4 interrupt These are interrupts that timer A generates 7)Timer B0 interrupt through timer B5 interrupt These are interrupts that timer B generates.
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 40 of 266
M16C/6KA Group
Interrupt
________
__________
8)INT0 interrupt through INT11 interrupt ______ ______ An INT interrupt occurs if either a rising edge or a falling edge or both edges are input to the INT pin. 9)IBF0 to IBF3, OBE interrupt These are interrupts that host bus interface generates. ______________ 10) LRESET interrupt ______________ ______________ LRESET interrupt occurs if an "L" is input to LRESET pin. 11)I2C0, I2C1, I2C2, SCL0, SDA0, SCL1, SDA1, SCL2, SDA2 interrupt These are interrupts that I2C bus interface generates. 12)PS20 to PS22 interrupt These are interrupt that PS2 interface generates.
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 41 of 266
M16C/6KA Group
Interrupt
Interrupts and Interrupt Vector Tables
If an interrupt request is accepted, a program branches to the interrupt routine set in the interrupt vector table. Set the first address of the interrupt routine in each vector table. Fig.DD-2 shows the format for specifying the address. Two types of interrupt vector tables are available -- fixed vector table in which addresses are fixed and variable vector table in which addresses can be varied by the setting.
MSB
LSB Low address Mid address 0000 High address 0000
Vector address + 0 Vector address + 1 Vector address + 2
0000
Fig.DD-2 Format for specifying interrupt vector addresses * Fixed vector tables The fixed vector table is a table in which addresses are fixed. The vector tables are located in an area extending from FFFDC16 to FFFFF16. One vector table comprises four bytes. Set the first address of interrupt routine in each vector table. Table.DD-1 shows the interrupts assigned to the fixed vector tables and addresses of vector tables. Table.DD-1 Interrupts assigned to the fixed vector tables and addresses of vector tables Interrupt source Undefined instruction Overflow BRK instruction Vector table addresses Address (L) to address (H) FFFDC16 to FFFDF16 FFFE016 to FFFE316 FFFE416 to FFFE716 Remarks Interrupt on UND instruction Interrupt on INTO instruction If the vector contains FF16, program execution starts from the address shown by the vector in the variable vector table There is an address-matching interrupt enable bit Do not use
Address match FFFE816 to FFFEB16 Single step (Note) FFFEC16 to FFFEF16 Watchdog timer FFFF016 to FFFF316 ________ DBC (Note) FFFF416 to FFFF716 Do not use _______ _______ NMI FFFF816 to FFFFB16 External interrupt by input to NMI pin Reset FFFFC16 to FFFFF16 Note: Interrupts used for debugging purposes only.
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 42 of 266
M16C/6KA Group
Interrupt
* Variable vector tables The addresses in the variable vector table can be modified, according to the user's settings. The start address of vector table is set to the interrupt table register (INTB). The 256-byte area subsequent that the start address is indicated by the INTB becomes the area for the variable vector tables. One vector table comprises 4 bytes. Set the first address of the interrupt routine in each vector table. Table.DD-2 shows the interrupts assigned to the variable vector tables and addresses of vector tables.
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 43 of 266
M16C/6KA Group
Interrupt
Table.DD-2 Interrupts assigned to the variable vector tables and addresses of vector
Software interrupt number Software interrupt number 0 Software interrupt number 1 Software interrupt number 4 Software interrupt number 5 Software interrupt number 6 Software interrupt number 7 Software interrupt number 8 Software interrupt number 10 Software interrupt number 11 Software interrupt number 12 Software interrupt number 13 Software interrupt number 14 Software interrupt number 15 Software interrupt number 16 Software interrupt number 17 Software interrupt number 18 Software interrupt number 19 Software interrupt number 20 Software interrupt number 21 Software interrupt number 22 Software interrupt number 23 Software interrupt number 24 Software interrupt number 27 Software interrupt number 28 Software interrupt number 31 Vector table address
Address (L) to address (H)
Interrupt source BRK instruction LRESET A-D IBF0 IBF1 IBF2 IBF3 Timer A0 Timer A1 Timer A2 Timer A3 Timer A4 Timer B0 Timer B1 Timer B2 Timer B3 Timer B4 Timer B5 OBE PS20 PS21 PS22 UART1 receive UART1 transmit Key input interrupt 0
Remarks Cannot be masked by I flag
+0 to +3 (Note 1) +4 to +7 (Note 1) +16 to +19 (Note 1) +20 to +23 (Note 1) +24 to +27 (Note 1) +28 to +31 (Note 1) +32 to +35 (Note 1) +40 to +43 (Note 1) +44 to +47 (Note 1) +48 to +51 (Note 1) +52 to +55 (Note 1) +56 to +59 (Note 1) +60 to +63 (Note 1) +64 to +67 (Note 1) +68 to +71 (Note 1) +72 to +75 (Note 1) +76 to +79 (Note 1) +80 to +83 (Note 1) +84 to +87 (Note 1) +88 to +91 (Note 1) +92 to +95 (Note 1) +96 to +99 (Note 1) +108 to +111 (Note 1) +112 to +115 (Note 1) +124 to +127 (Note 1)
Note 1: Address relative to address in interrupt table register (INTB).
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 44 of 266
M16C/6KA Group
Interrupt
Table.DD-3 Interrupts assigned to the variable vector tables and addresses of vector
Software interrupt number Software interrupt number 32 Software interrupt number 33 Software interrupt number 34 Software interrupt number 35 Software interrupt number 36 Software interrupt number 37 Software interrupt number 38 Software interrupt number 39 Software interrupt number 40 Software interrupt number 41 Software interrupt number 42 Software interrupt number 43 Software interrupt number 44 Software interrupt number 45 Software interrupt number 46 Software interrupt number 47 Software interrupt number 48 Software interrupt number 49 Software interrupt number 50 Software interrupt number 51 Software interrupt number 52 Software interrupt number 53 to Software interrupt number 63 Vector table address
Address (L) to address (H)
Interrupt source Key input interrupt 1 SIO3 SIO4 I2C0 SCL0, SDA0 I2C1 SCL1, SDA1 I2C2 SCL2, SDA2 INT0 INT1 INT2 INT3 INT4 INT5 INT6 INT7 INT8 INT9 INT10 INT11 Software interrupt
Remarks
+128 to +131(Note 1) +132 to +135 (Note 1) +136 to +139 (Note 1) +140to +143 (Note 1) +144 to +149 (Note 1) +148 to +151 (Note 1) +152 to +155 (Note 1) +156 to +159 (Note 1) +160 to +163(Note 1) +164 to +167 (Note 1) +168 to +171 (Note 1) +172 to +175 (Note 1) +176 to +179 (Note 1) +180 to +183(Note 1) +184 to +187 (Note 1) +188 to +191 (Note 1) +192 to +195 (Note 1) +196 to +199 (Note 1) +200 to +203 (Note 1) +204 to +207 (Note 1) +208 to +211 (Note 1) +212 to +215 (Note 1) to +252 to +255 (Note 1)
Cannot be masked by I flag
Note 1: Address relative to address in interrupt table register (INTB).
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 45 of 266
M16C/6KA Group
Interrupt
Interrupt Control
Descriptions are given here regarding how to enable or disable maskable interrupts and how to set the priority to be accepted. What is described here does not apply to non-maskable interrupts. Enable or disable a maskable interrupt using the interrupt enable flag (I flag), interrupt priority level selection bits and processor interrupt priority level (IPL). Whether an interrupt request is present or absent is indicated by the interrupt request bit. The interrupt request bit and the interrupt priority level selection bits are located in the interrupt control register of each interrupt. The interrupt enable flag (I flag) and the IPL are located in the flag register (FLG). Fig.DD-3 and DD-4 shows the memory map of the interrupt control registers.
Interrupt control register
Symbol LRSTIC ADIC IBFiIC(i=0 to 3) TAiIC(i=0 to 4) TBiIC(i=0 to 5) OBEIC PS2iIC(i=0 to 2) S1RIC S1TIC KUPiIC(i=0,1) SiIC(i=3,4) IICiIC(i=0 to 2) SCLDAiIC(i=0 to 2) Address 004116 004416 004516 to 004816 004A16 to 004E16 004F16 to 005416 005516 005616 to 005816 005B16 005C16 005F16,006016 006116,006216 006316,006516,006716 006416,006616,006816 When reset XXXXX0002 XXXXX0002 XXXXX0002 XXXXX0002 XXXXX0002 XXXXX0002 XXXXX0002 XXXXX0002 XXXXX0002 XXXXX0002 XXXXX0002 XXXXX0002 XXXXX0002
b7
b6
b5
b4
b3
b2
b1
b0
Bit symbol
ILVL0
Bit name
Interrupt priority level select bit
b2 b1 b0
Function
000: 001: 010: 011: 100: 101: 110: 111: Level 0 (interrupt disabled) Level 1 Level 2 Level 3 Level 4 Level 5 Level 6 Level 7
R
W
ILVL1
ILVL2
IR
Interrupt request bit
0 : Interrupt not requested 1 : Interrupt requested
(Note 1)
Nothing is assigned.
Note 1: Can only be writing by "0" (Please do not write "1" to this bit)
Fig.DD-3 Interrupt control registers(1)
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 46 of 266
M16C/6KA Group
Interrupt
b7
b6
b5
b4
b3
b2
b1
b0
0
Symbol INTiIC(i=0 to 11)
Address 006916 to 007416
When reset XX00X0002
Bit symbol
ILVL0
Bit name
Interrupt priority level select bit
b2 b1 b0
Function
0 0 0 : Level 0 (interrupt disabled) 0 0 1 : Level 1 0 1 0 : Level 2 0 1 1 : Level 3 1 0 0 : Level 4 1 0 1 : Level 5 1 1 0 : Level 6 1 1 1 : Level 7 0: Interrupt not requested 1: Interrupt requested 0 : Selects falling edge 1 : Selects rising edge Always set to "0"
R
W
ILVL1
ILVL2
IR
Interrupt request bit
(Note 1)
POL
Polarity select bit
Reserved bit Nothing is assigned.
Note 1: Can only be written by "0" (Please do not write "1" to this bit)
Fig.DD-4 Interrupt control registers (2)
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 47 of 266
M16C/6KA Group
Interrupt
Interrupt Enable Flag (I flag)
The interrupt enable flag (I flag) controls the enabling and disabling of maskable interrupts. Setting this flag to "1" enables all maskable interrupts; setting it to "0" disables all maskable interrupts. This flag is set to "0" after reset.
Interrupt Request Bit
The interrupt request bit is set to "1" by hardware when an interrupt is requested. After the interrupt is accepted and jumps to the corresponding interrupt vector, the request bit is set to "0" by hardware. The interrupt request bit can also be set to "0" by software. (Do not set this bit to "1").
Interrupt Priority Level Select Bits and Processor Interrupt Priority Level (IPL)
Set the interrupt priority level using the interrupt priority level select bits in the interrupt control register. When an interrupt request occurs, the interrupt priority level is compared with the IPL. The interrupt is enabled only when the priority level of the interrupt is higher than the IPL. Therefore, setting the interrupt priority level to "0" disables the interrupt. Table.DD-3 shows the settings of interrupt priority levels and Table.DD-4 shows the interrupt levels enabled, according to the consist of the IPL. The following are conditions under which an interrupt is accepted: * interrupt enable flag (I flag) = 1 * interrupt request bit = 1 * interrupt priority level > processor interrupt priority level (IPL) The interrupt enable flag (I flag), the interrupt request bit, the interrupt priority select bits, and the IPL are independent, and they are not affected each other.
Table.DD-4 Settings of interrupt priority levels
Interrupt priority level select bit
b2 b1 b0
Table.DD-5 Interrupt levels enabled according to the contents of the IPL
IPL
IPL2 IPL1 IPL0
Interrupt priority level
Priority order
Enabled interrupt priority levels
0 0 0 0 1 1 1 1
0 0 1 1 0 0 1 1
0 1 0 1 0 1 0 1
Level 0 (interrupt disabled) Level 1 Level 2 Level 3 Level 4 Level 5 Level 6 Level 7 High Low
0 0 0 0 1 1 1 1
0 0 1 1 0 0 1 1
0 1 0 1 0 1 0 1
Interrupt levels 1 and above are enabled Interrupt levels 2 and above are enabled Interrupt levels 3 and above are enabled Interrupt levels 4 and above are enabled Interrupt levels 5 and above are enabled Interrupt levels 6 and above are enabled Interrupt levels 7 and above are enabled All maskable interrupts are disabled
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 48 of 266
M16C/6KA Group
Interrupt
Rewrite the interrupt control register
To rewrite the interrupt control register, do so at a point that does not generate the interrupt request for that register. If there is possibility of the interrupt request occurrence, rewrite the interrupt control register after the interrupt is disabled. The program examples are described as follow:
Example 1:
INT_SWITCH1: FCLR I AND.B #00h, 0055h NOP NOP FSET I ; Disable interrupts. ; Clear TA0IC int. priority level and int. request bit. ; Four NOP instructions are required when using HOLD function. ; Enable interrupts.
Example 2:
INT_SWITCH2: FCLR I AND.B #00h, 0055h MOV.W MEM, R0 FSET I ; Disable interrupts. ; Clear TA0IC int. priority level and int. request bit. ; Dummy read. ; Enable interrupts.
Example 3:
INT_SWITCH3: PUSHC FLG FCLR I AND.B #00h, 0055h POPC FLG ; Push Flag register onto stack ; Disable interrupts. ; Clear TA0IC int. priority level and int. request bit. ; Enable interrupts.
The reason why two NOP instructions (four when using the HOLD function) or dummy read are inserted before FSET I in Examples 1 and 2 is to prevent the interrupt enable flag I from being set before the interrupt control register is rewritten due to effects of the instruction queue.
When a instruction to rewrite the interrupt control register is executed but the interrupt is disabled, the interrupt request bit is not set sometimes even if the interrupt request for that register has been generated. This will depend on the instruction. If this creates problems, use the below instructions to change the register. Instructions : AND, OR, BCLR, BSET
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 49 of 266
M16C/6KA Group
Interrupt
Interrupt Sequence
An interrupt sequence -- what are performed over a period from the instant an interrupt is accepted to the instant the interrupt routine is executed -- is described here. If an interrupt occurs during execution of an instruction, the processor determines its priority when the execution of the instruction is completed, and transfers control to the interrupt sequence from the next cycle. If an interrupt occurs during execution of either the SMOVB, SMOVF, SSTR or RMPA instruction, the processor temporarily suspends the instruction being executed, and transfers control to the interrupt sequence. In the interrupt sequence, the processor carries out the following in sequence given: (1) CPU gets the interrupt information (the interrupt number and interrupt request level) by reading address 0000016. (2) Saves the content of the flag register (FLG) as it was immediately before the start of interrupt sequence in the temporary register (Note) within the CPU. (3) Sets the interrupt enable flag (I flag), the debug flag (D flag), and the stack pointer select flag (U flag) to "0" . (4) Saves the content of the temporary register (Note) within the CPU in the stack area. (5) Saves the content of the program counter (PC) in the stack area. (6) Sets the interrupt priority level of the accepted instruction in the IPL. After the procession of interrupt sequence the processor executes instructions from the first address of the interrupt routine. Note: This register cannot be utilized by the user.
Interrupt Response Time
'Interrupt response time' is the period between the instant an interrupt occurs and the instant the first instruction within the interrupt routine has been executed. This time comprises the period from the occurrence of an interrupt to the completion of the instruction under execution at that moment (a) and the time required for executing the interrupt sequence (b). Fig.DD-5 shows the interrupt response time.
Interrupt request generated
Interrupt request acknowledged Time
Instruction (a)
Interrupt sequence (b)
Instruction in interrupt routine
Interrupt response time
Fig.DD-5 Interrupt response time
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 50 of 266
M16C/6KA Group
Interrupt
Time (a) is dependent on the instruction under execution. 30 cycles is the maximum required for the DIVX instruction (without wait). Time (b) is as shown in Table.DD-6 Table.DD-6 Time required for executing the interrupt sequence
Interrupt vector address Even Even Odd (Note 2) Odd (Note 2) Stack pointer (SP) value Even Odd Even Odd
________
16-Bit bus, without wait 18 cycles (Note 1) 19 cycles (Note 1) 19 cycles (Note 1) 20 cycles (Note 1)
8-Bit bus, without wait 20 cycles (Note 1) 20 cycles (Note 1) 20 cycles (Note 1) 20 cycles (Note 1)
Note 1: Add 2 cycles in the case of a DBC interrupt; add 1 cycle in the case either of an address coincidence interrupt or of a single-step interrupt. Note 2: Locate an interrupt vector address in an even address, if possible.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
BCLK Address bus Data bus R W The indeterminate segment is dependent on the queue buffer. If the queue buffer is ready to take an instruction, a read cycle occurs. Address 0000
Interrupt information
Indeterminate Indeterminate Indeterminate
SP-2 SP-2 contents
SP-4 SP-4 contents
vec vec contents
vec+2 vec+2 contents
PC
Fig.DD-6 Time required for executing the interrupt sequence
Variation of IPL when Interrupt Request is Accepted
If an interrupt request is accepted, the interrupt priority level of the accepted interrupt is set in the IPL. If an interrupt request, that does not have an interrupt priority level, is accepted, one of the values shown in Table.DD-7 is set in the IPL. Table.DD-7 Relationship between interrupts without interrupt priority levels and IPL Interrupt sources without priority levels
_______
Value set in the IPL 7 0 Not changed
Watchdog timer, NMI Reset Other
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 51 of 266
M16C/6KA Group
Interrupt
Saving Registers
In the interrupt sequence, only the contents of the flag register (FLG) and that of the program counter (PC) are saved in the stack area. First, the processor saves the four higher-order bits of the program counter, and 4 upper-order bits and 8 lower-order bits of the FLG register, 16 bits in total, in the stack area, then saves 16 lower-order bits of the program counter. Fig.DD-7 shows the state of the stack as it was before the acceptance of the interrupt request, and the state the stack after the acceptance of the interrupt request. Save other necessary registers at the beginning of the interrupt routine using software. Using the PUSHM instruction alone can save all the registers except the stack pointer (SP).
Address MSB Stack area LSB Address MSB Stack area LSB [SP] New stack pointer value
m-4 m-3 m-2 m-1 m m+1 Content of previous stack Content of previous stack [SP] Stack pointer value before interrupt occurs
m-4 m-3 m-2 m-1 m m+1
Program counter (PCL) Program counter (PCM) Flag register (FLGL) Flag register (FLGH) Program counter (PCH)
Content of previous stack Content of previous stack
Stack status before interrupt request is acknowledged
Stack status after interrupt request is acknowledged
Fig.DD-7 State of stack before and after acceptance of interrupt request The operation of saving registers carried out in the interrupt sequence is dependent on whether the content of the stack pointer, at the time of acceptance of an interrupt request, is even or odd. If the content of the stack pointer (Note) is even, the content of the flag register (FLG) and the content of the program counter (PC) are saved, 16 bits at a time. If odd, their contents are saved in two steps, 8 bits at a time. Fig.DD-8 shows the operation of the saving registers.
(1) Stack pointer (SP) contains even number
Address Stack area Sequence in which order registers are saved
(2) Stack pointer (SP) contains odd number
Address Stack area Sequence in which order registers are saved
[SP] - 5 (Odd) [SP] - 4 (Even) [SP] - 3 (Odd)
Program counter (PCL) Program counter (PCM)
[SP] - 5 (Even) [SP] - 4 (Odd) (2) Saved simultaneously, all 16 bits (1) Saved simultaneously, all 16 bits Finished saving registers in two operations. [SP] - 3 (Even) [SP] - 2 (Odd)
Program counter (PCL) Program counter (PCM) Flag register (FLGL) (FLGH)
Program counter (PCH)
(3) (4) (1) (2) Finished saving registers in four operations. Saved simultaneously, all 8 bits
[SP] - 2 (Even) Flag register (FLGL) [SP] - 1 (Odd) [SP] (Even)
Flag register Program (FLGH) counter (PCH)
[SP] - 1 (Even) Flag register [SP] (Odd)
Note: [SP] denotes the initial value of the stack pointer (SP) when interrupt request is acknowledged. After registers are saved, the SP content is [SP] minus 4.
Fig.DD-8 Operation of saving registers
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 52 of 266
M16C/6KA Group
Interrupt
Returning from an Interrupt Routine
Executing the REIT instruction at the end of an interrupt routine returns the contents of the flag register (FLG) as it was immediately before the start of interrupt sequence and the contents of the program counter (PC), both of which have been saved in the stack area. Then control returns to the program that was being executed before the acceptance of the interrupt request, so that the suspended process resumes. Return the other registers saved by software within the interrupt routine using the POPM or similar instruction before executing the REIT instruction.
Interrupt Priority
If there are two or more interrupt requests occurring at a point in time within a single sampling (checking whether interrupt requests are made), the interrupt assigned a higher priority is accepted. Assign an arbitrary priority to maskable interrupts (peripheral I/O interrupts) using the interrupt priority level select bits. If the same interrupt priority level is assigned, however, the interrupt with higher hardware priority is accepted. Priorities of the special interrupts, such as Reset (dealt with as an interrupt assigned the highest priority), watchdog timer interrupt, etc. are regulated by hardware. Fig.DD-9 shows the priorities of hardware interrupts. Software interrupts are not affected by the interrupt priority. If an instruction is executed, control branches invariably to the interrupt routine
Interrupt priority level judgement circuit
When two or more interrupts are generated simultaneously, this circuit selects the interrupt with the highest priority level. Fig.DD-10 shows the circuit that judges the interrupt priority level.
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 53 of 266
M16C/6KA Group
Interrupt
_______
________
Reset > NMI > DBC > Watchdog timer > Peripheral I/O > Single step > Address match
Fig.DD-9 Hardware interrupts priorities
Priority level of each interrupt
Level 0 (initial value)
INT11 INT9 INT7 INT10 INT8 INT5 INT3 INT1 SCL2, SDA2 SCL1, SDA1 SCL0, SDA0 S/IO4 Key input interrupt 1 INT6 INT4 INT2 INT0 I2C2 I2C1 I C0 SI/O3 UART1 transmission PS22 PS20
2
High
Priority level of each interrupt
Timer B5 Timer B3 Timer B1 Key input interrupt 0 UART1 reception PS21 OBE Timer B4 Timer B2 Timer A4 Timer A2 Timer A0 IBF3 IBF1 A-D conversion Timer B0 Timer A3 Timer A1 IBF2 IBF0 LRESET
Processor interrupt priority level(IPL)
Priority of peripheral I/O interrupts (if priority levels are same)
Low
To interrupt request level judgment output clock generation circuit (Fig. WA-2) Interrupt request accepted
Interrupt enable flag (I flag) Address match Watchdog timer DBC NMI RESET
Fig.DD-10 Interrupt priority judgement circuit
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 54 of 266
M16C/6KA Group
Interrupt
______
INT Interrupt
________ __________
INT0 to INT11 are triggered by the edges of external inputs. The edge polarity can be selected using the polarity select bit. As for external interrupt input, an interrupt can be generated both at the rising edge and at the falling edge by ________ setting "1" in the INTi interrupt polarity switching bit of the interrupt factor selection register0,1 (035F16, 035E16). To select both edges, set the polarity switching bit of the corresponding interrupt control register to `falling edge' ("0"). After the selection of interrupt edge, the corresponding interrupt request bit should be cleared to "0" before enabling the interrupt. Fig.DD-11, Fig.DD-12 show the Interrupt factor selection register 0, 1.
Interrupt factor selection register 0
b7 b6 b5 b4 b3 b2 b1 b0
00
Symbol IFSR0
Bit symbol
Address 035F16
When reset 0016
Bit name
INT0 interrupt polarity switching bit INT1 interrupt polarity switching bit INT2 interrupt polarity switching bit INT3 interrupt polarity switching bit INT4 interrupt polarity switching bit INT5 interrupt polarity switching bit
Function
0 : One edge 1 : Two edges 0 : One edge 1 : Two edges 0 : One edge 1 : Two edges 0 : One edge 1 : Two edges 0 : One edge 1 : Two edges 0 : One edge 1 : Two edges Must be "0"
RW
IFSR00 IFSR01 IFSR02 IFSR03 IFSR04 IFSR05
Reserved bits
Fig.DD-11 Interrupt factor selection register(1)
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 55 of 266
M16C/6KA Group
Interrupt
Interrupt factor selection register 1
b7 b6 b5 b4 b3 b2 b1 b0
00
Symbol IFSR 5
Address 035E16
When reset 0016
Bit symbol
IFSR10
Bit name
INT6 interrupt polarity switching bit
Function
0 : One edge 1 : Two edge 0 : One edge 1 : Two edge 0 : One edge 1 : Two edge 0 : One edge 1 : Two edge 0 : One edge 1 : Two edge 0 : One edge 1 : Two edge Must be "0"
RW
IFSR11
INT7 interrupt polarity switching bit
IFSR12
INT8 interrupt polarity switching bit
IFSR13
INT9 interrupt polarity switching bit
IFSR14
INT10 interrupt polarity switching bit
IFSR15
INT11 interrupt polarity switching bit
Reserved bits
Fig. DD-12 Interrupt factor selection register(4)
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 56 of 266
M16C/6KA Group
Interrupt
______
NMI Interrupt
______ ______ ______
An NMI interrupt is generated when the input to the P85/NMI pin changes from "H" to "L". The NMI interrupt is a non-maskable external interrupt. The pin level can be checked in the port P85 register (bit 5 at address 03F016). This pin cannot be used as a normal port input.
Key Input Interrupt 0
If the direction register of any of P50 to P57 is set for input and a falling edge is input to that port, a key input interrupt 0 is generated. A key input interrupt 0 can also be used as a key-on wakeup function for cancelling the wait mode or stop mode. Fig.DD-13 shows the block diagram of the key input interrupt 0. Note that if an "L" level is input to any pin that has not been disabled for input, inputs to the other pins are not detected as an interrupt.
Pull-up transistor
Pull-up select bit Key input interrupt 0 control register Port P57 direction register Port P57 direction register (address 004D16)
P57/KI07 Pull-up transistor P56/KI06 Pull-up transistor Port P56 direction register Key input interrupt 0 request
Interrupt control circuit
Port P55 direction register
P55/KI05 Port P54 direction register
Pull-up transistor P54/KI04 Pull-up transistor P53/KI03 Pull-up transistor
Port P53 direction register
Port P52 direction register
P52/KI02 Port P51 direction register
Pull-up transistor P51/KI01
Pull-up transistor P50/KI00
Port P50 direction register
Fig.DD-13 Block diagram of key input interrupt 0
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 57 of 266
M16C/6KA Group
Interrupt
Key Input Interrupt 1
If any of the bits of key input interrupt 1 enable register (Address: 02F416) are set to "1", the key input interrupt 1 request occurs when a falling or a rising edge is input to one of the corresponding pins. The effective input edge of key input interrupt 1 is determined by the edge selection bit of key input interrupt 1 edge selection register (Address: 02F516). When the bit is set to "0", at the falling edge, when the bit is set to "1", at the rising edge of the input signal to the corresponding pin, the interrupt request occurs respectively. When an effective rising edge or falling edge is input, "1" is set to the corresponding bit of P14 event register (Address: 02F616). By reading the register after the interrupt occurs, the pin, which the effective edge is input, can be confirmed even if the status of that pin has been changed. At the completion of the reading of P14 event register, the bits, whose value is "1" in reading, will be cleared automatically. A dummy write clears the register too. The registers, the block diagram and the timing of key input interrupt 1 are shown in Fig. DD-15, Fig. DD-16 and Fig. DD-17 respectively. After changing the enable/disable setting of key input interrupt1 register or changing the effective edge by modifying key input interrupt 1 edge selection register, the value of P14 event register and interrupt request bit may become "1". A dummy write to the P14 event register and a clear to the interrupt request bit should be done after changing the effective edge.
P14 event register
b7 b6 b5 b4 b3 b2 b1 b0
Symbol KIN1EV
Address 02F616
When reset 0016
Bit symbol
KIN1EV0
Bit name
P14 event bit 0
Function
0 : Factor 1 : No factor 0 : Factor 1 : No factor 0 : Factor 1 : No factor 0 : Factor 1 : No factor 0 : Factor 1 : No factor 0 : Factor 1 : No factor 0 : Factor 1 : No factor 0 : Factor 1 : No factor
RW
KIN1EV1
P14 event bit 1
KIN1EV2
P14 event bit 2
KIN1EV3
P14 event bit 3
KIN1EV4
P14 event bit 4
KIN1EV5
P14 event bit 5
KIN1EV6
P14 event bit 6
KIN1EV7
P14 event bit 7
Fig.DD-14 P14 event register
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z page 58 of 266
M16C/6KA Group
Interrupt
Key input interrupt 1 enable register
b7 b6 b5 b4 b3 b2 b1 b0
Symbol KIN1EN
Address 02F416
When reset 0016
Bit Symbol
KIN1EN0 KIN1EN1 KIN1EN2 KIN1EN3 KIN1EN4 KIN1EN5 KIN1EN6 KIN1EN7
Bit name
Function
RW
0 : Disable Key input interrupt 1 enable bit 0 1 : Enable 0 : Disable Key input interrupt 1 enable bit 1 1 : Enable 0 : Disable Key input interrupt 1 enable bit 2 1 : Enable 0 : Disable Key input interrupt 1 enable bit 3 1 : Enable 0 : Disable Key input interrupt 1 enable bit 4 1 : Enable 0 : Disable Key input interrupt 1 enable bit 5 1 : Enable Key input interrupt 1 enable bit 6 0 : Disable 1 : Enable Key input interrupt 1 enable bit 7 0 : Disable 1 : Enable
Key input interrupt 1 edge selection register
b7 b6 b5 b4 b3 b2 b1 b0
Symbol KIN1SEL
Address 02F516
When reset 0016
Bit Symbol
KIN1SEL0 KIN1SEL1 KIN1SEL2 KIN1SEL3 KIN1SEL4 KIN1SEL5 KIN1SEL6 KIN1SEL7
Bit name Key input interrupt 1 edge selection bit 0 Key input interrupt 1 edge selection bit 1 Key input interrupt 1 edge selection bit 2 Key input interrupt 1 edge selection bit 3 Key input interrupt 1 edge selection bit 4 Key input interrupt 1 edge selection bit 5 Key input interrupt 1 edge selection bit 6 Key input interrupt 1 edge selection bit 7
Function 0 : Falling edge 1 : Rising edge 0 : Falling edge 1 : Rising edge 0 : Falling edge 1 : Rising edge 0 : Falling edge 1 : Rising edge 0 : Falling edge 1 : Rising edge 0 : Falling edge 1 : Rising edge 0 : Falling edge 1 : Rising edge 0 : Falling edge 1 : Rising edge
RW
Fig.DD-15 Key input interrupt 1 registers
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 59 of 266
Key input interrupt 1 control register (Address 005C16)
Pull-up transistor P147 direction register Interrupt control circuit Key input interrupt 1 request
M16C/6KA Group
Pull-up selection bit
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
Key input interrupt 1 edge selection bit7 P147 event latch circuit Event data Event register D Q DB7 S Q The read from address 02F616
Edge selection one-shot generation circuit
Key input interrupt 1 enable bit 7
P147/KI17 RESET The read from address 02F616 R The read from address 02F616 R
Interrupt
Fig.DD-16 The block diagram of key input interrupt 1
Q D R Delay circuit The read from address 02F616 Key input interrupt 1 edge selection bit6
Edge selection one-shot generation circuit
page 60 of 266
The read from address 02F616 P146 event latch circuit The write to address 02F616 The read from address 02F616 P145 event latch circuit The write to address 02F616 The read from address 02F616 P144 event latch circuit The write to address 02F616 The read from address 02F616 P143 event latch circuit The write to address 02F616 The read from address 02F616 P142 event latch circuit The write to address 02F616 The read from address 02F616 P141 event latch circuit The write to address 02F616 The read from address 02F616 P140 event latch circuit The write to address 02F616 The read from address 02F616 DB6 The read from address 02F616 DB5 The read from address 02F616 DB4 Key input interrupt 1 edge selection bit5
Edge selection one-shot generation circuit
Pull-up transistor
Key input interrupt 1 enable bit 6
P146/KI16
Pull-up transistor Key input interrupt 1 edge selection bit4
Edge selection one-shot generation circuit
Key input interrupt 1 enable bit 5
P145/KI15
Pull-up transistor
Key input interrupt 1 enable bit 4
P144/KI14 Key input interrupt 1 edge selection bit3
Edge selection one-shot generation circuit
Pull-up transistor Key input interrupt 1 edge selection bit2
Edge selection one-shot generation circuit
Key input interrupt 1 enable bit 3
The read from address 02F616 DB3
P143/KI13
Pull-up transistor
Key input interrupt 1 enable bit 2
The read from address 02F616 DB2 The read from address 02F616 DB1
P142/KI12 Key input interrupt 1 edge selection bit1
Edge selection one-shot generation circuit
Pull-up transistor Key input interrupt 1 edge selection bit0
Edge selection one-shot generation circuit
Key input interrupt 1 enable bit 1
P141/KI11
Pull-up transistor
Key input interrupt 1 enable bit 0
The read from address 02F616 DB0
P140/KI10
M16C/6KA Group
Interrupt
P140 P141 (Note 1)
P140 request P141 request
Interrupt request bit P140 event data (Note 2) P141 event data P14 event register 0016
0116
0316
0016
The read signal from 02F616 The read from 02F616 Interrupt procession
0116
0316 Interrupt procession
0016 Interrupt procession
Note 1: If there are several effective edge inputs, the input sequential order can not be confirmed. Note 2: If another interrupt request occurs between the setting of prior key input interrupt 1 request bit and the read of P14 event register, the interrupt request bit will be set again same as P14 event register. After the read of P14 event register, both the bits, which were set to "1", will be automatically cleared. However, the interrupt processing will be executed twice because of the re-setting of interrupt request bit (the value of P14 event register in the 2nd reading will be "0").
Fig.DD-17 The timing of key input interrupt 1
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 61 of 266
M16C/6KA Group
Address match interrupt
Address Match Interrupt
An address match interrupt is generated when the address match interrupt address register contents match the program counter value. Two address match interrupts can be set, each of which can be enabled and disabled by an address match interrupt enable bit. Address match interrupts are not affected by the interrupt enable flag (I flag) and processor interrupt priority level (IPL). The stacked value of the program counter (PC) for an address match interrupt varies depending on the instruction being executed. Fig.DD-18 shows the address match interrupt-related registers.
Address match interrupt enable register
b7 b6 b5 b4 b3 b2 b1 b0
Symbol AIER Bit symbol
Address 000916 Bit name Address match interrupt 0 enable bit Address match interrupt 1 enable bit
When reset XXXXXX002 Function 0 : Interrupt disabled 1 : Interrupt enabled 0 : Interrupt disabled 1 : Interrupt enabled RW
AIER0 AIER1
Nothing is assigned. In an attempt to write to these bits, write "0". The value, if read, turns out to be indeterminate.
Address match interrupt register i (i = 0, 1)
(b23) b7 (b19) b3 (b16)(b15) b0 b7 (b8) b0 b7 b0
Symbol RMAD0 RMAD1
Address 001216 to 001016 001616 to 001416
When reset X0000016 X0000016
Function Address setting register for address match interrupt
Values that can be set R W 0000016 to FFFFF16
Nothing is assigned. In an attempt to write to these bits, write "0". The value, if read, turns out to be indeterminate.
Fig.DD-18 Address match interrupt-related registers
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 62 of 266
M16C/6KA Group
Precautions for interrupts
Precautions for Interrupts (1) Reading address 0000016
* When maskable interrupt is occurred, CPU read the interrupt information (the interrupt number and interrupt request level) in the interrupt sequence. The interrupt request bit of the certain interrupt written in address 0000016 will then be set to "0". Reading address 0000016 by software sets the request bit, which the interrupt source is enabled with the highest priority, to "0". Though the interrupt is generated, the interrupt routine may not be executed. Hence do not read address 0000016 by software.
(2) Setting the stack pointer
* The value of the stack pointer is initialized to 000016 right after the reset. Accepting an interrupt before setting a value in the stack pointer may become a factor of runaway. Be sure to set a value in the _______ stack pointer before accepting an interrupt. When using the NMI interrupt, initialize the stack point at the beginning of a program. Concerning the first instruction immediately after reset, generating any interrupts
_______
including the NMI interrupt is prohibited.
_______
(3) The NMI interrupt
_______
* As for the NMI interrupt pin, an interrupt cannot be disabled. Connect it to the Vcc pin via a resistor (pullup) if unused. Be sure to work on it. _______ * The NMI pin also serves as P85, which is exclusively input. Reading the contents of the P8 register allows reading the pin value. Use the reading of this pin only for establishing the pin level at the time _______ when the NMI interrupt is input. _______ * Do not reset the CPU with the input to the NMI pin being in the "L" state. _______ * Do not attempt to go into stop mode with the input to the NMI pin being in the "L" state. With the input to the _______ NMI being in the "L" state, the CM10 is fixed to "0", so attempting to go into stop mode is turned down. _______ * Do not attempt to go into wait mode with the input to the NMI pin being in the "L" state. With the input to the _______ NMI pin being in the "L" state, the CPU stops but the oscillation does not stop, so no power is saved. In this instance, the CPU is returned to the normal state by a later interrupt. _______ * Signals input to the NMI pin require an "L" level of 1 clock or more, from the operation clock of the CPU.
(4) External interrupt
________
* Either an "L" level or an "H" level of at least 380 ns width is necessary for the signal input to pins INT0 _________ through INT11 regardless of the CPU operation clock. ________ _________ * When the polarity of the INT0 to INT11 pins is changed, the interrupt request bit is sometimes set to "1". After changing the polarity, set the interrupt request bit to "0". Fig.DD-19 shows the procedure for changing ______ the INT interrupt generate factor.
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 63 of 266
M16C/6KA Group
Precautions for interrupts
Clear the interrupt enable flag to "0" (Disable interrupt)
Set the interrupt priority level to level 0 (Disable INTi interrupt)
Set the polarity select bit
Clear the interrupt request bit to "0"
Set the interrupt priority level to level 1 to 7 (Enable the accepting of INTi interrupt request)
Set the interrupt enable flag to "1" (Enable interrupt)
______
Fig.DD-19 Switching condition of INT interrupt request (5) Rewrite the interrupt control register * To rewrite the interrupt control register, do so at a point that does not generate the interrupt request for that register. If there is possibility of the interrupt request occurs, rewrite the interrupt control register after the interrupt is disabled. The program examples are described as follow: * When a instruction to rewrite the interrupt control register is executed when the interrupt is disabled, the
Example 1:
INT_SWITCH1: FCLR I AND.B #00h, 0055h NOP NOP FSET I ; Disable interrupts. ; Clear TA0IC int. priority level and int. request bit. ; Four NOP instructions are required when using HOLD function. ; Enable interrupts.
Example 2:
INT_SWITCH2: FCLR I AND.B #00h, 0055h MOV.W MEM, R0 FSET I ; Disable interrupts. ; Clear TA0IC int. priority level and int. request bit. ; Dummy read. ; Enable interrupts.
Example 3:
INT_SWITCH3: PUSHC FLG FCLR I AND.B #00h, 0055h POPC FLG ; Push Flag register onto stack ; Disable interrupts. ; Clear TA0IC int. priority level and int. request bit. ; Enable interrupts.
The reason why two NOP instructions (four when using the HOLD function) or dummy read are inserted before FSET I in Examples 1 and 2 is to prevent the interrupt enable flag I from being set before the interrupt control register is rewritten due to effects of the instruction queue.
interrupt request bit is not set sometimes even if the interrupt request for that register has been generated. This will depend on the instruction. If this creates problems, use the below instructions to change the register. Instructions : AND, OR, BCLR, BSET
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 64 of 266
M16C/6KA Group
Watchdog Timer
Watchdog Timer
The watchdog timer has the function of detecting when the program is out of control. The watchdog timer is a 15-bit counter which down-counts the clock derived by dividing the BCLK using the prescaler. A watchdog timer interrupt is generated when an underflow occurs in the watchdog timer. Bit 7 of the watchdog timer control register (address 000F16) selects the prescaler division ratio (by 16 or by 128). Thus the watchdog timer's period can be calculated as given below. The watchdog timer's period is, however, subject to an error due to the prescaler.
With XIN chosen for BCLK Watchdog timer period = prescaler dividing ratio (16 or 128) X watchdog timer count (32768) BCLK
For example, suppose that BCLK runs at 16 MHz and that 16 has been chosen for the dividing ratio of the prescaler, then the watchdog timer's period becomes approximately 32.7 ms. The watchdog timer is initialized by writing to the watchdog timer start register (address 000E16) and when a watchdog timer interrupt request is generated. The prescaler is initialized only when the microcomputer is reset. After a reset is cancelled, the watchdog timer and prescaler are both stopped. The count is started by writing to the watchdog timer start register (address 000E16). Fig.DG-1 shows the block diagram of the watchdog timer. Fig.DG-2 shows the watchdog timer-related registers.
Prescaler
"WDC7 = 0"
1/16
BCLK HOLD
1/128
"WDC7 = 1"
Watchdog timer
Watchdog timer interrupt request
Write to the watchdog timer start register (address 000E16) RESET
Set to "7FFF16"
Fig.DG-1 Block diagram of watchdog timer
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 65 of 266
M16C/6KA Group
Watchdog Timer
Watchdog timer control register
b7 b6 b5 b4 b3 b2 b1 b0
00
Symbol WDC Bit symbol
Address 000F16 Bit name
When reset 000XXXXX2 Function RW
High-order bit of watchdog timer Reserved bit Reserved bit
WDC7
Must always be set to "0" Must always be set to "0" Prescaler select bit 0 : Divided by 16 1 : Divided by 128
Watchdog timer start register
b7 b0
Symbol WDTS
Address 000E16
When reset Indeterminate RW
Function The watchdog timer is initialized and starts counting after a write instruction to this register. The watchdog timer value is always initialized to "7FFF16" regardless of whatever value is written.
Fig.DG-2 Watchdog timer control and start registers
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 66 of 266
M16C/6KA Group
Timer
Timer
There are eleven 16-bit timers. These timers can be classified by function into timers A (five) and timers B (six). All these timers function independently. Fig.FB-1 and FB-2 show the block diagram of timers.
XIN 1/8 1/4 f1 f8 f32
f1 f8 f32
* Timer mode * One-shot mode * PWM mode
TA0IN
Noise filter
Timer A0
* Event counter mode
Timer A0 interrupt
* Timer mode * One-shot mode * PWM mode
Timer A1 interrupt Timer A1
TA1IN
Noise filter
* Event counter mode * Timer mode * One-shot mode * PWM mode
Timer A2 interrupt Timer A2
TA2IN
Noise filter
* Event counter mode
* Timer mode * One-shot mode * PWM mode
Timer A3 interrupt Timer A3
TA3IN
Noise filter
* Event counter mode * Timer mode * One-shot mode * PWM mode
Timer A4 interrupt TA4IN
Noise filter
Timer A4
* Event counter mode
Timer B2 overflow
Note 1: The TA0IN pin (P71) is shared with TB5IN pin, so be careful.
Fig.FB-1 Timer A block diagram
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 67 of 266
M16C/6KA Group
Timer
XIN 1/8 1/4 f1 f8 f32 Timer A
f1 f8 f32
* Timer mode * Pulse width measuring mode
TB0IN
Noise filter
Timer B0 interrupt
Timer B0
* Event counter mode
* Timer mode * Pulse width measuring mode
TB1IN
Noise filter
Timer B1 interrupt
Timer B1
* Event counter mode
* Timer mode * Pulse width measuring mode
Timer B2 interrupt
TB2IN
Noise filter
Timer B2
* Event counter mode
* Timer mode * Pulse width measuring mode
Timer B3 interrupt
TB3IN
Noise filter
Timer B3
* Event counter mode
* Timer mode * Pulse width measuring mode
Timer B4 interrupt
TB4IN
Noise filter
Timer B4
* Event counter mode
* Timer mode * Pulse width measuring mode
Timer B5 interrupt
TB5IN
Noise filter
Timer B5
* Event counter mode
Note 1: The TB5IN pin (P71) is shared with TA0IN pin, so be careful.
Fig.FB-2 Timer B block diagram
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 68 of 266
M16C/6KA Group
Timer A
Timer A
Fig.FB-3 shows the block diagram of timer A. Fig.FB-4 to FB-6 show the timer A-related registers. Except in event counter mode, timers A0 through A4 all have the same function. Use the timer Ai mode register (i = 0 to 4) bits 0 and 1 to choose the desired mode. Timer A has the four operation modes listed as follows: * Timer mode: The timer counts an internal count source. * Event counter mode: The timer counts pulses from an external source or a timer over flow. * One-shot timer mode: The timer stops counting when the count reaches "000016". * Pulse width modulation (PWM) mode: The timer continually outputs pulse with arbitrary width.
Data bus high-order bits
Clock source selection
f1 f8 f32
* Timer * One shot * PWM * Timer (gate function) * Event counter
Data bus low-order bits Low-order 8 bits Reload register (16) High-order 8 bits
Polarity selection
TAiIN (i = 0 to 4)
Counter (16) Clock selection
Up count/down count Always down count except in event counter mode TAi Timer A0 Timer A1 Timer A2 Timer A3 Timer A4 Addresses 038716 038616 038916 038816 038B16 038A16 038D16 038C16 038F16 038E16 TAj Timer A4 Timer A0 Timer A1 Timer A2 Timer A3 TAk Timer A1 Timer A2 Timer A3 Timer A4 Timer A0
Count start flag
(Address 038016)
TB2 overflow TAj overflow
(j = i - 1. Note, however, that j = 4 when i = 0) External trigger
Down count
Up/down flag
(Address 038416)
TAk overflow
(k = i + 1. Note, however, that k = 0 when i = 4)
TAiOUT
(i = 0 to 4)
Pulse output
Toggle flip-flop
Fig.FB-3 Block diagram of timer A
Timer Ai mode register
b7 b6 b5 b4 b3 b2 b1 b0
Symbol TAiMR(i=0 to 4)
Address When reset 039616 to 039A16 0016
Bit symbol
TMOD0
Bit name
b1 b0
Function
0 1 : Event counter mode 1 0 : One-shot timer mode 1 1 : Pulse width modulation (PWM) mode
RW
Operation mode selection bits 0 0 : Timer mode
TMOD1
MR0 MR1 MR2 MR3 TCK0 TCK1
Function varies with each operation mode
Count source selection bits (Function varies with each operation mode)
Fig.FB-4 Timer A-related registers (1)
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z page 69 of 266
M16C/6KA Group
Timer A
Timer Ai register (Note)
(b15) b7 (b8) b0 b7 b0
Symbol TA0 TA1 TA2 TA3 TA4
Address 038716,038616 038916,038816 038B16,038A16 038D16,038C16 038F16,038E16
When reset Indeterminate Indeterminate Indeterminate Indeterminate Indeterminate
Function * Timer mode Count the internal count source * Event counter mode Count pulses from external input or the overflow of timer * One-shot timer mode Count one shot width * Pulse width modulation mode (16-bit PWM) Function as a 16-bit pulse width modulator * Pulse width modulation mode (8-bit PWM) Timer low-order address functions as an 8-bit prescaler and high-order address functions as an 8-bit pulse width modulator
Values that can be set
RW
000016 to FFFF16 000016 to FFFF16
000016 to FFFF16
000016 to FFFE16 0016 to FE16 (Both high-order and low-order addresses)
Note: Read and write data in 16-bit units.
Count start flag
b7 b6 b5 b4 b3 b2 b1 b0
Symbol TABSR
Address 038016
When reset 0016
Bit symbol TA0S TA1S TA2S TA3S TA4S TB0S TB1S TB2S
Bit name Timer A0 count start flag Timer A1 count start flag Timer A2 count start flag Timer A3 count start flag Timer A4 count start flag Timer B0 count start flag Timer B1 count start flag Timer B2 count start flag
Function 0 : Stop count 1 : Start count
RW
Up/down flag
b7 b6 b5 b4 b3 b2 b1 b0
Symbol UDF
Address 038416
When reset 0016
Bit symbol TA0UD TA1UD TA2UD TA3UD TA4UD TA2P TA3P TA4P
Bit name Timer A0 up/down flag Timer A1 up/down flag Timer A2 up/down flag Timer A3 up/down flag Timer A4 up/down flag
Function 0 : Down count 1 : Up count This specification becomes valid when the up/down flag content is selected for up/down switching factor
RW
Timer A2 two-phase pulse 0 : two-phase pulse signal processing disabled signal processing select bit 1 : two-phase pulse signal Timer A3 two-phase pulse processing enabled signal processing select bit When not using the two-phase Timer A4 two-phase pulse pulse signal processing function, signal processing select bit set the select bit to "0"
Fig.FB-5 Timer A-related registers (2)
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z page 70 of 266
M16C/6KA Group
Timer A
One-shot start flag
b7 b6 b5 b4 b3 b2 b1 b0
Symbol ONSF
Address 038216
When reset 00X000002
Bit symbol
TA0OS TA1OS TA2OS TA3OS TA4OS
Bit name Timer A0 one-shot start flag Timer A1 one-shot start flag Timer A2 one-shot start flag Timer A3 one-shot start flag Timer A4 one-shot start flag
Function 1 : Timer start When read, the value is "0"
RW
Nothing is assigned. In an attempt to write to this bit, write "0". The value, if read, turns out to be indeterminate. TA0TGL TA0TGH
Timer A0 event/trigger selection bits
b7 b6
0 0 : Input on TA0IN is selected (Note) 0 1 : TB2 overflow is selected 1 0 : TA4 overflow is selected 1 1 : TA1 overflow is selected
Note: Set the corresponding port direction register to "0".
Trigger selection register
b7 b6 b5 b4 b3 b2 b1 b0
Symbol TRGSR
Address 038316
When reset 0016
Bit symbol
TA1TGL
Bit name Timer A1 event/trigger selection bits
b1 b0
Function 0 0 : Input on TA1IN is selected (Note) 0 1 : TB2 overflow is selected 1 0 : TA0 overflow is selected 1 1 : TA2 overflow is selected
b3 b2
RW
TA1TGH
TA2TGL
Timer A2 event/trigger selection bits
TA2TGH
0 0 : Input on TA2IN is selected (Note) 0 1 : TB2 overflow is selected 1 0 : TA1 overflow is selected 1 1 : TA3 overflow is selected
b5 b4
TA3TGL TA3TGH
Timer A3 event/trigger selection bits
0 0 : Input on TA3IN is selected (Note) 0 1 : TB2 overflow is selected 1 0 : TA2 overflow is selected 1 1 : TA4 overflow is selected
b7 b6
TA4TGL TA4TGH
Timer A4 event/trigger selection bits
0 0 : Input on TA4IN is selected (Note) 0 1 : TB2 overflow is selected 1 0 : TA3 overflow is selected 1 1 : TA0 overflow is selected
Note: Set the corresponding port direction register to "0".
Fig.FB-6 Timer A-related registers (3)
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 71 of 266
M16C/6KA Group
Timer A
(1) Timer mode In this mode, the timer counts an internally generated count source. (See Table.FB-1) Fig.FB-7 shows the timer Ai mode register in timer mode. Table.FB-1 Specifications of timer mode Item Count source Count operation Divide ratio Count start condition Count stop condition Interrupt request generation timing TAiIN pin function TAiOUT pin function Read from timer Write to timer Specification f1, f8, f32 * Down count * When the timer underflows, it reloads the reload register contents and then continuing counting 1/(n+1) n : Set value Count start flag is set (= 1) Count start flag is reset (= 0) When the timer underflows Programmable I/O port or gate input Programmable I/O port or pulse output Count value can be read out by reading timer Ai register * When counting stopped When a value is written to timer Ai register, it is written to both reload register and counter * When counting in progress When a value is written to timer Ai register, it is written to only reload register (Transferred to counter at next reload time) * Gate function Counting can be started and stopped by the TAiIN pin's input signal * Pulse output function Each time the timer underflows, the TAiOUT pin's polarity is reversed
Select function
Timer Ai mode register
b7 b6 b5 b4 b3 b2 b1 b0
0
00
Symbol TAiMR(i=0 to 4) Bit symbol TMOD0 TMOD1 MR0
Address When reset 039616 to 039A16 0016 Bit name Function
b1 b0
RW
Operation mode selection bits Pulse output function selection bit
0 0 : Timer mode 0 : Pulse is not output (TAiOUT pin is a normal port pin) 1 : Pulse is output (Note 1) (TAiOUT pin is a pulse output pin)
b4 b3
MR1
Gate function selection bits 0 X (Note 2): Gate function not available
(TAiIN pin is a normal port pin)
MR2
1 0 : Timer counts only when TAiIN pin is held "L" (Note 3) 1 1 : Timer counts only when TAiIN pin is held "H" (Note 3) 0 (Must always be fixed to "0" in timer mode) Count source selection bits
b7 b6
MR3 TCK0 TCK1
0 0 : f1 0 1 : f8 1 0 : f32 1 1 : Inhibited
Note 1: The settings of the corresponding port register and port direction register are invalid. Note 2: The bit can be "0" or "1". Note 3: Set the corresponding port direction register to "0".
Fig.FB-7 Timer Ai mode register in timer mode
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z page 72 of 266
M16C/6KA Group
Timer A
(2) Event counter mode In this mode, the timer counts an external signal or an internal timer's overflow. Timers A0 and A1 can count a single-phase external signal. Timers A2, A3, and A4 can count a single-phase and a two-phase external signals. Table.FB-2 lists timer specifications and Fig. FB-8 shows the timer Ai mode register in event count mode when counting a single-phase external signal. Table.FB-3 lists timer specifications and Fig. FB-8 shows the timer Ai mode register in event count mode when counting a two-phase external signals. Table.FB-2 Timer specifications in event counter mode (when not processing two-phase pulse signal) Item Specification Count source * External signal input to TAiIN pin (effective edge can be selected by software) * TB2 overflow, TAj overflow Count operation * Up count or down count can be selected by external signal or software * When the timer overflows or underflows, it reloads the reload register con tents and then continuing counting (Note) Divide ratio 1/ (FFFF16 - n + 1) for up count 1/ (n + 1) for down count n : Set value Count start condition Count start flag is set (= 1) Count stop condition Count start flag is reset (= 0) Interrupt request generation timing The timer overflows or underflows TAiIN pin function Programmable I/O port or count source input TAiOUT pin function Programmable I/O port, pulse output, or up/down count select input Read from timer Count value can be read out by reading timer Ai register Write to timer * When counting stopped When a value is written to timer Ai register, it is written to both reload register and counter * When counting in progress When a value is written to timer Ai register, it is written to only reload register (Transferred to counter at next reload time) Select function * Free-run count function Even when the timer overflows or underflows, the reload register content is not reloaded to it * Pulse output function Each time the timer overflows or underflows, the TAiOUT pin's polarity is reversed Note: This does not apply when the free-run function is selected.
Timer Ai mode register
b7 b6 b5 b4 b3 b2 b1 b0
0
01
Symbol TAiMR(i = 0, 1) Bit symbol TMOD0 TMOD1 MR0
Address 039616, 039716
When reset 0016 Function RW RW
Bit name Operation mode selection bits Pulse output function selection bit
b1 b0
0 1 : Event counter mode (Note 1) 0 : Pulse is not output (TAiOUT pin is a normal port pin) 1 : Pulse is output (Note 2) (TAiOUT pin is a pulse output pin) 0 : Counts external signal's falling edge 1 : Counts external signal's rising edge 0 : Up/down flag's content 1 : TAiOUT pin's input signal (Note 4)
MR1 MR2 MR3 TCK0 TCK1
Count polarity selection bit (Note 3) Up/down switching factor selection bit
0 (Must always be fixed to "0" in event counter mode) Count operation type selection bit 0 : Reload type 1 : Free-run type
Invalid in event counter mode Can be "0" or "1"
Note 1: In event counter mode, the count source is selected by the event / trigger select bit (addresses 038216 and 038316). Note 2: The settings of the corresponding port register and port direction register are invalid. Note 3: Valid only when counting an external signal. Note 4: When an "L" signal is input to the TAiOUT pin, the downcount is activated. When "H", the upcount is activated. Set the corresponding port direction register to "0".
Fig.FB-8 Timer Ai mode register in event counter mode
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z page 73 of 266
M16C/6KA Group
Timer A
Table.FB-3 Timer specifications in event counter mode (when processing two-phase pulse signals with timers A2, A3, and A4) Item Count source Count operation Specification * Two-phase pulse signals input to TAiIN and TAiOUT pin * Up count or down count can be selected by two-phase pulse signals * When the timer overflows or underflows, the reload register content is reloaded and the timer starts over again (Note) 1/ (FFFF16 - n + 1) for up count 1/ (n + 1) for down count n : Set value Count start flag is set (= 1) Count start flag is reset (= 0) Timer overflows or underflows Two-phase pulse input Two-phase pulse input Count value can be read out by reading timer A2, A3, or A4 register * When counting stopped When a value is written to timer A2, A3, or A4 register, it is written to both reload register and counter * When counting in progress When a value is written to timer A2, A3, or A4 register, it is written to only reload register. (Transferred to counter at next reload time.) * Normal processing operation The timer up-counts by the rising edge of TAiIN pin and down-counts by the falling edge fo TAiIN pin during the "H" level period of input signal in TAiOUT pin.
Divide ratio Count start condition Count stop condition
Interrupt request generation timing
TAiIN pin function TAiOUT pin function Read from timer Write to timer
Select function
TAiOUT TAiIN (i=2,3)
Up count
Up count
Up count
Down count
Down count
Down count
* Multiply-by-4 processing operation If the phase relationship is such that the TAiIN pin goes "H" when the input signal on the TAiOUT pin is "H", the timer counts up rising and falling edges on the TAiOUT and TAiIN pins. If the phase relationship is such that the TAiIN pin goes "L" when the input signal on the TAiOUT pin is "H", the timer counts down rising and falling edges on the TAiOUT and TAiIN pins.
TAiOUT
Count up all edges Count down all edges
TAiIN (i=3,4)
Count up all edges Count down all edges
Note: This does not apply when the free-run function is selected.
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z page 74 of 266
M16C/6KA Group
Timer A
Timer Ai mode register (When not using two-phase pulse signals' processing)
b7 b6 b5 b4 b3 b2 b1 b0
0
01
Symbol Address When reset TAiMR(i = 2 to 4) 039816 to 039A16 0016
Bit symbol
TMOD0 TMOD1 MR0
Bit name
Operation mode selection bits Pulse output function selection bit
b1 b0
Function
0 1 : Event counter mode 0 : Pulse is not output (TAiOUT pin is a normal port pin) 1 : Pulse is output (Note 1) (TAiOUT pin is a pulse output pin)
RW
MR1 MR2 MR3 TCK0 TCK1
Count polarity selection bit 0 : Counts external signal's falling edges 1 : Counts external signal's rising edges (Note 2) Up/down switching factor selection bit Count operation type selection bit Two-phase pulse signals' processing operation selection bit (Note 4)(Note 5) 0 : Up/down flag's content 1 : TAiOUT pin's input signal (Note 3)
0 : (Must always be "0" in event counter mode) 0 : Reload type 1 : Free-run type 0 : Normal processing operation 1 : Multiply-by-4 processing operation
Note 1: The settings of the corresponding port register and port direction register are invalid. Note 2: This bit is valid when only counting an external signal. Note 3: Set the corresponding port direction register to "0". Note 4: This bit is valid for the timer A3 mode register. For timer A2 and A4 mode registers, this bit can be "0 "or "1". Note 5: When performing two-phase signal processing, make sure the two-phase pulse signals' processing operation selection bit (address 038416) is set to "1". Also, always be sure to set the event/trigger selection bit (addresses 038216 and 038316) to "00".
Timer Ai mode register (When using two-phase pulse signals' processing)
b7 b6 b5 b4 b3 b2 b1 b0
010001
Symbol Address When reset TAiMR(i = 2 to 4) 039816 to 039A16 0016
Bit symbol
TMOD0 TMOD1 MR0 MR1 MR2 MR3 TCK0 TCK1
Bit name
Operation mode selection bits
b1 b0
Function
0 1 : Event counter mode
RW
0 (Must always be "0" when using two-phase pulse signal processing) 0 (Must always be "0" when using two-phase pulse signal processing) 1 (Must always be "1" when using two-phase pulse signal processing) 0 (Must always be "0" when using two-phase pulse signal processing) Count operation type selection bit 0 : Reload type 1 : Free-run type
Two-phase pulse processing 0 : Normal processing operation operation selection bit 1 : Multiply-by-4 processing operation (Note 1)(Note 2)
Note 1: This bit is valid for timer A3 mode register. For timer A2 and A4 mode registers, this bit can be "0" or "1". Note 2: When performing two-phase pulse signals' processing, make sure the two-phase pulse signals' processing operation selection bit (address 038416) is set to "1". Also, always be sure to set the event/trigger selection bit (addresses 038216 and 038316) to "00".
Fig.FB-9 Timer Ai mode register in event counter mode
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 75 of 266
M16C/6KA Group
Timer A
(3) One-shot timer mode In this mode, the timer operates only once. (See Table.FB-4) When a trigger occurs, the timer starts to operate for a given period. Fig.FB-10 shows the timer Ai mode register in one-shot timer mode. Table.FB-4 Timer specifications in one-shot timer mode Item Specification Count source Count operation f1, f8, f32 * The timer counts down * When the count reaches 000016, the timer stops counting after reloading a new count * If a trigger occurs when counting, the timer reloads a new count and restarts counting 1/n n : Set value * An external trigger is input * The timer overflows * The one-shot start flag is set (= 1) * A new count is reloaded after the count has reached 000016 * The count start flag is reset (= 0) The count reaches 000016 Programmable I/O port or trigger input Programmable I/O port or pulse output When timer Ai register is read, it indicates an indeterminate value * When counting stopped When a value is written to timer Ai register, it is written to both reload register and counter * When counting in progress When a value is written to timer Ai register, it is written to only reload register (Transferred to counter at next reload time)
Divide ratio Count start condition
Count stop condition
Interrupt request generation timing
TAiIN pin function TAiOUT pin function Read from timer Write to timer
Timer Ai mode register
b7 b6 b5 b4 b3 b2 b1 b0
0
10
Symbol Address When reset TAiMR(i = 0 to 4) 039616 to 039A16 0016 Bit symbol TMOD0 TMOD1 MR0 Bit name Operation mode selection bits Pulse output function selection bit
b1 b0
Function 1 0 : One-shot timer mode 0 : Pulse is not output (TAiOUT pin is a normal port pin) 1 : Pulse is output (Note 1) (TAiOUT pin is a pulse output pin)
RW
MR1 MR2
External trigger selection 0 : Falling edge of TAiIN pin's input signal (Note 3) bit (Note 2) 1 : Rising edge of TAiIN pin's input signal (Note 3) Trigger selection bit 0 : One-shot start flag is valid 1 : Selected by event/trigger selection register
MR3 TCK0 TCK1
0 (Must always be "0" in one-shot timer mode) Count source selection bits
b7 b6
0 0 : f1 0 1 : f8 1 0 : f32 1 1 : Inhibited
Note 1: The settings of the corresponding port register and port direction register are invalid. Note 2: Valid only when the TAiIN pin is selected by the event/trigger selection bit (addresses 038216 and 038316). If timer overflow is selected, this bit can be "1" or "0". Note 3: Set the corresponding port direction register to "0".
Fig.FB-10 Timer Ai mode register in one-shot timer mode
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 76 of 266
M16C/6KA Group
Timer A
(4) Pulse width modulation (PWM) mode In this mode, the timer outputs pulses of a given width in succession. (See Table.FB-5) In this mode, the counter functions as either a 16-bit pulse width modulator or an 8-bit pulse width modulator. Fig.FB-11 shows the timer Ai mode register in pulse width modulation mode. Fig.FB-12 shows the example of how a 16-bit pulse width modulator operates. Fig.FB-13 shows the example of how an 8-bit pulse width modulator operates. Table.FB-5 Timer specifications in pulse width modulation mode
Item
Count source Count operation
Specification
f1, f8, f32 * The timer counts down (operating as an 8-bit or a 16-bit pulse width modulator) * The timer reloads a new count at a rising edge of PWM pulse and continues counting * The timer is not affected by a trigger that occurs when counting * High level width n / fi n : Set value * Cycle time (216-1) / fi fixed * High level width n (m+1) / fi n : values set to timer Ai register's high-order address 8-1) (m+1) / fi * Cycle time (2 m : values set to timer Ai register's low-order address * External trigger is input * The timer overflows * The count start flag is set (= 1) * The count start flag is reset (= 0) The falling edge of PWM pulse Programmable I/O port or trigger input Pulse output When timer Ai register is read, it indicates an indeterminate value * When counting stopped When a value is written to timer Ai register, it is written to both reload register and counter * When counting in progress When a value is written to timer Ai register, it is written to only reload register (Transferred to counter at next reload time)
16-bit PWM 8-bit PWM Count start condition
Count stop condition Interrupt request generation timing TAiIN pin function TAiOUT pin function Read from timer Write to timer
Timer Ai mode register
b7 b6 b5 b4 b3 b2 b1 b0
11
1
Symbol TAiMR(i=0 to 4) Bit symbol TMOD0 TMOD1 MR0 MR1 MR2 MR3 TCK0 TCK1
Address When reset 039616 to 039A16 0016 Function
b1 b0
Bit name Operation mode selection bits 1 1 : PWM mode
RW
1 (Must always be "1" in PWM mode) External trigger selection 0: Falling edge of TAiIN pin's input signal (Note 2) bit (Note 1) 1: Rising edge of TAiIN pin's input signal (Note 2) Trigger selection bit 16/8-bit PWM mode selection bit Count source selection bits 0: Count start flag is valid 1: Selected by event/trigger selection register
0: Functions as a 16-bit pulse width modulator 1: Functions as an 8-bit pulse width modulator
b7 b6
0 0 : f1 0 1 : f8 1 0 : f32 1 1 : Inhibited
Note 1: Valid only when the TAiIN pin is selected by the event/trigger selection bit (addresses 038216 and 038316). If timer overflow is selected, this bit can be "1" or "0". Note 2: Set the corresponding port direction register to "0".
Fig.FB-11 Timer Ai mode register in pulse width modulation mode
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z page 77 of 266
M16C/6KA Group
Timer A
Condition : Reload register = 000316, when external trigger (rising edge of TAiIN pin input signal) is selected
1 / fi X (2 16 - 1)
Count source
TAiIN pin input signal
"H" "L"
Trigger is not generated by this signal 1 / fi X n
PWM pulse output from TAiOUT pin Timer Ai interrupt request bit
"H" "L" "1" "0"
fi : Frequency of count source Cleared to "0" when interrupt request is accepted, or cleared by software (f1, f8, f32) Note: n = 000016 to FFFE16.
Fig.FB-12 Example of how a 16-bit pulse width modulator operates
Condition : Reload register high-order 8 bits = 0216 Reload register low-order 8 bits = 0216 External trigger (falling edge of TAiIN pin input signal) is selected
1 / fi X (m + 1) X (2 8 - 1) Count source (Note1)
TAiIN pin input signal
"H" "L"
1 / fi X (m + 1)
"H" Underflow signal of 8-bit prescaler (Note2) "L"
1 / fi X (m + 1) X n PWM pulse output from TAiOUT pin Timer Ai interrupt request bit
"H" "L" "1" "0"
fi : Frequency of count source (f1, f8, f32)
Cleared to "0" when interrupt request is accepted, or cleared by software
Note 1: The 8-bit prescaler counts the count source. Note 2: The 8-bit pulse width modulator counts the 8-bit prescaler's underflow signal. Note 3: m = 0016 to FE16; n = 0016 to FE16.
Fig.FB-13 Example of how an 8-bit pulse width modulator operates
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z page 78 of 266
M16C/6KA Group
Timer B
Timer B
Fig.FB-14 shows the block diagram of timer B. Fig.FB-15 and FB-16 show the timer B-related registers. Use the timer Bi mode register (i = 0 to 5) bits 0 and 1 to choose the desired mode. Timer B has three operation modes listed as follows: * Timer mode: The timer counts an internal count source. * Event counter mode: The timer counts pulses from an external source or a timer overflow. * Pulse period/pulse width measuring mode: The timer measures an external signal's pulse period or pulse width.
Data bus high-order bits Data bus low-order bits Low-order 8 bits High-order 8 bits
Clock source selection
f1 f8 f32
* Timer * Pulse period/pulse width measurement
Reload register (16)
* Event counter TBiIN (i = 0 to 5) Polarity switching and edge pulse Count start flag (address 038016) Counter reset circuit Can be selected in only event counter mode TBj overflow (j = i - 1. Note, however, j = 2 when i = 0, j = 5 when i = 3) TBi Timer B0 Timer B1 Timer B2 Timer B3 Timer B4 Timer B5
Counter (16)
Address 039116 039016 039316 039216 039516 039416 035116 035016 035316 035216 035516 035416
TBj Timer B2 Timer B0 Timer B1 Timer B5 Timer B3 Timer B4
Fig.FB-14 Block diagram of timer B
Timer Bi mode register
b7 b6 b5 b4 b3 b2 b1 b0
Symbol Address TBiMR(i = 0 to 5) 039B16 to 039D16 035B16 to 035D16
When reset 00XX00002 00XX00002
Bit symbol
TMOD0 TMOD1
Bit name
b1 b0
Function
0 0 : Timer mode 0 1 : Event counter mode 1 0 : Pulse period/pulse width measurement mode 1 1 : Inhibited
R
W
Operation mode selection bits
MR0 MR1 MR2
Function varies with each operation mode
(Note 1) (Note 2)
MR3 TCK0 TCK1 Count source selection bits (Function varies with each operation mode)
Note 1: Timer B0, timer B3. Note 2: Timer B1, timer B2, timer B4, timer B5.
Fig.FB-15 Timer B-related registers (1)
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z page 79 of 266
M16C/6KA Group
Timer B
Timer Bi register (Note)
(b15) b7 (b8) b0 b7 b0
Symbol TB0 TB1 TB2 TB3 TB4 TB5
Address 039116, 039016 039316, 039216 039516, 039416 035116, 035016 035316, 035216 035516, 035416
When reset Indeterminate Indeterminate Indeterminate Indeterminate Indeterminate Indeterminate
Values that can be set
Function
* Timer mode Counts the timer's period * Event counter mode Counts external pulses input or a timer overflow * Pulse period / pulse width measurement mode Measures a pulse period or width
RW
000016 to FFFF16
000016 to FFFF16
Note: Read and write data in 16-bit units.
Count start flag
b7 b6 b5 b4 b3 b2 b1 b0
Symbol TABSR
Address 038016
When reset 0016
Bit symbol TA0S TA1S TA2S TA3S TA4S TB0S TB1S TB2S
Bit name
Timer A0 count start flag Timer A1 count start flag Timer A2 count start flag Timer A3 count start flag Timer A4 count start flag Timer B0 count start flag Timer B1 count start flag Timer B2 count start flag
Function
0 : Stops counting 1 : Starts counting
RW
Timer B3, 4, 5 count start flag
b7 b6 b5 b4 b3 b2 b1 b0
Symbol TBSR
Address 034016
When reset 000XXXXX2
Bit symbol
Bit name
Function
RW
Nothing is assigned. In an attempt to write to these bits, write "0". The value, if read, turns out to be indeterminate. TB3S TB4S TB5S Timer B3 count start flag Timer B4 count start flag Timer B5 count start flag 0 : Stops counting 1 : Starts counting
Fig.FB-16 Timer B-related registers (2)
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 80 of 266
M16C/6KA Group
Timer B
(1) Timer mode
In this mode, the timer counts an internally generated count source. (See Table.FB-6.) Fig.FB-17 shows the timer Bi mode register in timer mode. Table.FB-6 Timer specifications in timer mode Item Specification Count source f1, f8, f32 Count operation *Counts down *When the timer underflows, it reloads the reload register contents and then continuing counting Divide ratio 1/(n+1) n : Set value Count start condition Count start flag is set (= 1) Count stop condition Count start flag is reset (= 0) Interrupt request generation timing The timer underflows TBiIN pin function Read from timer Write to timer Programmable I/O port Count value is read out by reading timer Bi register *When counting stopped When a value is written to timer Bi register, it is written to both reload register and counter * When counting in progress When a value is written to timer Bi register, it is written to only reload register (Transferred to counter at next reload time)
Timer Bi mode register
b7 b6 b5 b4 b3 b2 b1 b0
00
Symbol TBiMR(i=0 to 5)
Address 039B16 to 039D16 035B16 to 035D16
When reset 00XX00002 00XX00002
Bit symbol TMOD0 TMOD1 MR0 MR1 MR2
Bit name
Operation mode selection bits Invalid in timer mode Can be "0" or "1" 0 (Set to "0" in timer mode ; i = 0, 3)
b1 b0
Function
0 0 : Timer mode
R
W
(Note 1)
Nothing is assigned (i = 1, 2, 4, 5). In an attempt to write to this bit, write "0". The value, if read, turns out to be indeterminate.
(Note 2)
MR3
Invalid in timer mode. In an attempt to write to this bit, write "0". The value, if read in timer mode, turns out to be indeterminate. Count source selection bits
b7 b6
TCK0 TCK1
0 0 : f1 0 1 : f8 1 0 : f32 1 1 : Inhibited
Note 1: Timer B0, timer B3. Note 2: Timer B1, timer B2, timer B4, timer B5.
Fig.FB-17 Timer Bi mode register in timer mode
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z page 81 of 266
M16C/6KA Group
Timer B
(2) Event counter mode
In this mode, the timer counts an external signal or an internal timer's overflow. (See Table.FB-7) Fig.FB-18 shows the timer Bi mode register in event counter mode. Table.FB-7 Timer specifications in event counter mode Item Specification Count source *External signals input to TBiIN pin *Effective edge of count source can be a rising edge, a falling edge, or both edges as selected by software Count operation *Counts down *When the timer underflows, it reloads the reload register contents and then continuing counting Divide ratio 1/(n+1) n : Set value Count start condition Count start flag is set (= 1) Count stop condition Count start flag is reset (= 0) Interrupt request generation timing The timer underflows TBiIN pin function Count source input Read from timer Count value can be read out by reading timer Bi register Write to timer *When counting stopped When a value is written to timer Bi register, it is written to both reload register and counter *When counting in progress When a value is written to timer Bi register, it is written to only reload register (Transferred to counter at next reload time)
Timer Bi mode register
b7 b6 b5 b4 b3 b2 b1 b0
01
Symbol TBiMR(i=0 to 5)
Address 039B16 to 039D16 035B16 to 035D16
When reset 00XX00002 00XX00002
Bit symbol
TMOD0 TMOD1 MR0
Bit name
Operation mode selection bits Count polarity selection bits (Note 1)
b1 b0
Function
0 1 : Event counter mode
b3 b2
R
W
MR1
0 0 : Counts external signal's falling edges 0 1 : Counts external signal's rising edges 1 0 : Counts external signal's falling and rising edges 1 1 : Inhibited
(Note 2)
MR2
0 (Fixed to "0" in event counter mode; i = 0, 3) Nothing is assigned (i = 1, 2, 4, 5). In an attempt to write to this bit, write "0". The value, if read, turns out to be indeterminate.
(Note 3)
MR3
Invalid in event counter mode. In an attempt to write to this bit, write "0". The value, if read in event counter mode, turns out to be indeterminate. Invalid in event counter mode. Can be "0" or "1". Event clock selection 0 : Input from TBiIN pin (Note 4) 1 : TBj overflow
(j = i - 1; however, j = 2 when i = 0, j = 5 when i = 3)
TCK0 TCK1
Note 1: Valid only when input from the TBiIN pin is selected as the event clock. If timer's overflow is selected, this bit can be "0" or "1". Note 2: Timer B0, timer B3. Note 3: Timer B1, timer B2, timer B4, timer B5. Note 4: Set the corresponding port direction register to "0".
Fig.FB-18 Timer Bi mode register in event counter mode
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z page 82 of 266
M16C/6KA Group
Timer B
(3) Pulse period/pulse width measurement mode
In this mode, the timer measures the pulse period or pulse width of an external signal. (See Table.FB-8) Fig.FB-19 shows the timer Bi mode register in pulse period/pulse width measurement mode. Fig.FB-20 shows the operation timing when measuring a pulse period. Fig.FB-21 shows the operation timing when measuring a pulse width. Table.FB-8 Timer specifications in pulse period/pulse width measurement mode Item Count source Count operation Specification f1, f8, f32 *Up count *At measurement pulse's effective edge, after the count value is transferred to reload register, it is cleared to "000016" and then continues counting. Count start flag is set (= 1) Count start flag is reset (= 0) *When measurement pulse's effective edge is input (Note 1) *When an overflow occurs. (Simultaneously, the timer Bi overflow flag becomes "1". The timer Bi overflow flag becomes "0" when the count start flag is "1" and a value is written to the timer Bi mode register.)
Count start condition Count stop condition Interrupt request generation timing
Measurement pulse input When timer Bi register is read, it indicates the reload register's content (measurement result) (Note 2) Write to timer Cannot be written to Note 1 : An interrupt request is not generated when the first effective edge is input after the timer has started counting. Note 2 : After count starts, the value read out from the timer Bi register is indeterminate until the second effective edge is input .
Timer Bi mode register
b7 b6 b5 b4 b3 b2 b1 b0
TBiIN pin function Read from timer
10
Symbol TBiMR(i=0 to 5)
Address 039B16 to 039D16 035B16 to 035D16
When reset 00XX00002 00XX00002
Bit symbol
TMOD0 TMOD1 MR0
Bit name
Operation mode selection bits Measurement mode selection bits
b1 b0
Function
1 0 : Pulse period / pulse width measurement mode
b3 b2
R
W
MR1
0 0 : Pulse period measurement (Interval between measurement pulse's falling edge to falling edge) 0 1 : Pulse period measurement (Interval between measurement pulse's rising edge to rising edge) 1 0 : Pulse width measurement (Interval between measurement pulse's falling edge to rising edge, and between rising edge to falling edge) 1 1 : Inhibited
MR2
0 (Fixed to "0" in pulse period/pulse width measurement mode; i = 0, 3) Nothing is assigned (i = 1, 2, 4, 5). In an attempt to write to this bit, write "0". The value, if read, turns out to be indeterminate.
(Note 2)
(Note 3)
MR3 TCK0 TCK1
Timer Bi overflow flag ( Note 1) Count source selection bits
0 : Timer did not overflow 1 : Timer has overflowed
b7 b6
0 0 : f1 0 1 : f8 1 0 : f32 1 1 : Inhibited
Note 1: The timer Bi overflow flag becomes "0" when the count start flag is "1" and a value is written to the timer Bi mode register. This flag cannot be set to "1" by software. Note 2: Timer B0, timer B3. Note 3: Timer B1, timer B2, timer B4, timer B5.
Fig.FB-19 Timer Bi mode register in pulse period/pulse width measurement mode
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z page 83 of 266
M16C/6KA Group
Timer B
When measuring a pulse time interval from falling edge to falling edge
Count source
Measurement pulse
"H" "L" Transfer (indeterminate value) Transfer (measured value)
Reload register transfer timing
counter (Note 1) (Note 1) (Note 2)
Timing at which counter reaches "000016" Count start flag
"1" "0"
Timer Bi interrupt request bit
"1" "0"
Cleared to "0" when interrupt request is accepted, or cleared by software. Timer Bi overflow flag
"1" "0"
Note 1: Counter is initialized at completion of measurement. Note 2: Timer has overflowed.
Fig.FB-20 Operation timing when measuring a pulse period
Count source
Measurement pulse
"H" "L"
Transfer (indeterminate value) Transfer (measured value) Transfer (measured value) Transfer (measured value)
Reload register transfer timing
counter
(Note 1)
(Note 1)
(Note 1)
(Note 1)
(Note 2)
Timing at which counter reaches "000016" Count start flag
"1" "0"
Timer Bi interrupt request bit
"1" "0"
Cleared to "0" when interrupt request is accepted, or cleared by software. Timer Bi overflow flag
"1" "0"
Note 1: Counter is initialized at completion of measurement. Note 2: Timer has overflowed.
Fig.FB-21 Operation timing when measuring a pulse width
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z page 84 of 266
M16C/6KA Group
Serial I/O
Serial I/O
Serial I/O is configured as three channels: UART1, S I/O3 and S I/O4.
UART1
Fig.GA-1 shows the block diagram of UART1. Fig.GA-2 shows the block diagram of the transmit/receive unit. UART1 has two operation modes: a clock synchronous serial I/O mode and a clock asynchronous serial I/O mode (UART mode). The contents of the serial I/O mode selection bits (bits 0 to 2 at address 03A816) determine whether UART1 is used as a clock synchronous serial I/O or as a UART. Although a few functions are different, UART1 has almost the same functions. Table.GA-1 shows the functions of UART1, and Fig.GA-3 to GA-7 show the registers related to UART1. Table.GA-1 Functions of UART1
Function CLK polarity selection LSB first / MSB first selection Continuous receive mode selection Transfer clock output from multiple pins selection Serial data logic switch TxD, RxD I/O polarity switch TxD, RxD port output format UART1 Possible Possible Possible Possible Possible Possible CMOS output (Note 1) (Note 1) (Note 1) (Note 1)
Note 1: Only in clock synchronous serial I/O mode.
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 85 of 266
M16C/6KA Group
Serial I/O
(UART1)
RxD1
RxD polarity switching circuit
1/16
UART reception Reception control circuit
Clock source selection
f1 f8 f32 Bit rate generator Internal (address 03A916)
Receive clock
Clock synchronous type UART transmission
1/16
Transmit/ receive unit
TxD polarity switching circuit
TxD1
1 / (n1+1)
External
Clock synchronous type Clock synchronous type
(when internal clock is selected) 1/2
Transmission control circuit
Transmit clock
CLK1 CTS1 / RTS1 / CLKS1
CLK polarity switching circuit
Clock synchronous type (when internal clock is selected)
Clock synchronous type (when external clock is selected)
CTS/RTS disabled
RTS1
Clock output pin select switch VCC CTS/RTS disabled
CTS1
n1 : Values set to UART1 bit rate generator (BRG1)
Fig.GA-1 Block diagram of UART1
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 86 of 266
M16C/6KA Group
Serial I/O
No reverse
RXD1
RxD data reverse circuit
Reverse
Clock synchronous type
1SP SP 2SP SP
PAR
PAR disabled
Clock synchronous type
UART (7 bits) UART (8 bits)
UART(7 bits)
UART1 receive register
PAR enabled
UART
UART (9 bits)
Clock synchronous type
UART (8 bits) UART (9 bits)
0
0
0
0
0
0
0
D8
D7
D6
D5
D4
D3
D2
D1
D0
Logic reverse circuit + MSB/LSB conversion circuit
UART1 receive buffer register Address 03AE16 Address 03AF16
Data bus high-order bits Data bus low-order bits
Logic reverse circuit + MSB/LSB conversion circuit
D8
D7
D6
D5
D4
D3
D2
D1
D0
UART1 transmit buffer register Address 03AA16 Address 03AB16
UART (8 bits) UART (9 bits)
PAR enabled
UART (9 bits) UART
Clock synchronous type
2SP SP SP 1SP
PAR
PAR disabled
Clock synchronous type
"0"
UART (7 bits) UART (8 bits)
Clock synchronous type
UART(7 bits)
UART1 transmit register
Not reverse
TxD data reverse circuit
Reverse
TXD1
SP: Stop bit PAR: Parity bit
Fig.GA-2 Block diagram of UART1 transmit/receive unit
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 87 of 266
M16C/6KA Group
Serial I/O
UART1 transmit buffer register
(b15) b7 (b8) b0 b7 b0
Symbol U1TB
Address 03AB16, 03AA16
When reset Indeterminate Function
RW
Transmit data Nothing is assigned. In an attempt to write to these bits, write "0". The value, if read, turn out to be indeterminate.
UART1 receive buffer register
(b15) b7 (b8) b0 b7 b0
Symbol U1RB
Address 03AF16, 03AE16
When reset Indeterminate
Bit symbol
Bit name
Function (During clock synchronous serial I/O mode) Receive data
Function (During UART mode) Receive data
RW
Nothing is assigned. In an attempt to write to these bits, write "0". The value, if read, turns out to be "0". OER FER PER SUM Overrun error flag (Note 1) 0 : No overrun error 1 : Overrun error found Framing error flag (Note 1) Invalid Parity error flag (Note 1) Error sum flag (Note 1) Invalid Invalid 0 : No overrun error 1 : Overrun error found 0 : No framing error 1 : Framing error found 0 : No parity error 1 : Parity error found 0 : No error 1 : Error found
Note 1: Bits 15 through 12 are set to "0" when the serial I/O mode selection bits (bits 2 to 0 at address 03A816) are set to "0002" or the receive enable bit is set to "0". (Bit 15 is set to "0" when bits 14 to 12 all are set to "0".) Bits 14 and 13 are also set to "0" when the lower byte of the UART1 receive buffer register (address 03AE16) is read out.
UART1 bit rate generator
b7 b0
Symbol U1BRG
Address 03A916 Function
When reset Indeterminate Values that can be set 0016 to FF16 RW
Assuming that set value = n, BRG1 divides the count source by n+1
Fig.GA-3 Serial I/O-related registers (1)
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 88 of 266
M16C/6KA Group
Serial I/O
UART1 transmit/receive mode register
b7 b6 b5 b4 b3 b2 b1 b0
Symbol U1MR
Address 03A816
When reset 0016
Bit symbol SMD0 SMD1 SMD2
Bit name Serial I/O mode selection bits
Function (During clock synchronous serial I/O mode) Must be fixed to 001
b2 b1 b0
Function (During UART mode)
b2 b1 b0
RW
0 0 0 : Serial I/O invalid 0 1 0 : Inhibited 0 1 1 : Inhibited 1 1 1 : Inhibited
1 0 0 : Transfer data 7 bits long 1 0 1 : Transfer data 8 bits long 1 1 0 : Transfer data 9 bits long 0 0 0 : Serial I/O invalid 0 1 0 : Inhibited 0 1 1 : Inhibited 1 1 1 : Inhibited Must always be "0" 0 : One stop bit 1 : Two stop bits Valid when bit 6 = "1" 0 : Odd parity 1 : Even parity 0 : Parity disabled 1 : Parity enabled 0 : Sleep mode deselected 1 : Sleep mode selected 0 : Not reverse 1 : Reverse Usually set to "0"
CKDIR Internal/external clock selection bit STPS PRY Stop bit length selection bit
0 : Internal clock 1 : External clock (Note 1) Invalid
Odd/even parity selection Invalid bit Parity enable bit Sleep selection bit Invalid Must always be "0" 0 : Not reverse 1 : Reverse Usually set to "0"
PRYE SLEP
IOPOL TxD, RxD I/O polarity switching bit
Note 1: Set the corresponding port direction register to "0".
Fig.GA-4 Serial I/O-related registers (2)
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 89 of 266
M16C/6KA Group
Serial I/O
UART1 transmit/receive control register 0
b7 b6 b5 b4 b3 b2 b1 b0
Symbol U1C0 Bit symbol CLK0 CLK1 CRS CTS/RTS function selection bit
Address 03AC16
When reset 0816 Function (During clock synchronous serial I/O mode) Function (During UART mode)
b1 b0
Bit name BRG count source selection bits
b1 b0
RW
0 0 : f1 is selected 0 1 : f8 is selected 1 0 : f32 is selected 1 1 : Inhibited Valid when bit 4 = "0" 0 : CTS function is selected (Note 1) 1 : RTS function is selected (Note 2) 0 : Data present in transmit register (during transmission) 1 : No data present in transmit register (transmission completed) 0 : CTS/RTS function enabled 1 : CTS/RTS function disabled (Pins function as programmable I/O port) 0 : TXD1 pin is CMOS output 1 : TXD1 pin is N-channel opendrain output
0 0 : f1 is selected 0 1 : f8 is selected 1 0 : f32 is selected 1 1 : Inhibited Valid when bit 4 = "0" 0 : CTS function is selected (Note 1) 1 : RTS function is selected (Note 2) 0 : Data present in transmit register (during transmission) 1 : No data present in transmit register (transmission completed) 0 : CTS/RTS function enabled 1 : CTS/RTS function disabled (Pins function as programmable I/O port) 0: TXD1 pin is CMOS output 1: TXD1 pin is N-channel open-drain output Must always be "0"
TXEPT Transmit register empty flag
CRD
CTS/RTS disable bit
NCH
Data output selection bit
CKPOL CLK polarity selection bit 0 : Transmit data is output at falling edge of transfer clock and receive data is input at rising edge 1 : Transmit data is output at rising edge of transfer clock and receive data is input at falling edge UFORM Transfer format selection 0 : LSB first 1 : MSB first bit (Note 3)
0 : LSB first 1 : MSB first
Note 1: Set the corresponding port direction register to "0". Note 2: The settings of the corresponding port register and port direction register are invalid. Note 3: Only clock synchronous serial I/O mode and 8-bit UART mode are valid.
Fig.GA-5 Serial I/O-related registers (3)
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 90 of 266
M16C/6KA Group
Serial I/O
UART1 transmit/receive control register 1
b7 b6 b5 b4 b3 b2 b1 b0
Symbol U1C1
Address 03AD16
When reset 0216 Function (During clock synchronous serial I/O mode) 0 : Transmission disabled 1 : Transmission enabled 0 : Data present in transmit buffer register 1 : No data present in transmit buffer register 0 : Reception disabled 1 : Reception enabled 0 : No data present in receive buffer register 1 : Data present in receive buffer register
Bit symbol TE TI
Bit name Transmit enable bit Transmit buffer empty flag
Function (During UART mode) 0 : Transmission disabled 1 : Transmission enabled 0 : Data present in transmit buffer register 1 : No data present in transmit buffer register 0 : Reception disabled 1 : Reception enabled 0 : No data present in receive buffer register 1 : Data present in receive buffer register
RW
RE RI
Receive enable bit Receive complete flag
Nothing is assigned. In an attempt to write to these bits, write "0". The value, if read, turns out to be "0". U1LCH Data logic selection bit 0 : Not reverse 1 : Reverse 0 : Not reverse 1 : Reverse
Nothing is assigned. In an attempt to write to these bits, write "0". The value, if read, turns out to be "0".
Fig.GA-6 Serial I/O-related registers (4)
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 91 of 266
M16C/6KA Group
Serial I/O
UART transmit/receive control register 2
b7 b6 b5 b4 b3 b2 b1 b0
0
0
0
Bit symbol
Symbol UCON
Address 03B016
When reset X00000002 Function (During clock synchronous serial I/O mode) Function (During UART mode)
Bit name
RW
Reserved bit U1IRS UART1 transmit interrupt factor selection bit
Must always be "0" 0 : Transmit buffer empty (Tl = 1) 0 : Transmit buffer empty (Tl = 1) 1 : Transmission completed 1 : Transmission completed (TXEPT = 1) (TXEPT = 1) Must always be "0" 0 : Continuous receive mode disabled 1 : Continuous receive mode enabled Valid when bit 5 = "1" 0 : Clock output to CLK1 1 : Clock output to CLKS1 Invalid
Reserved bit U1RRM UART1 continuous receive mode enable bit
CLKMD0 CLK/CLKS selection bit 0
Invalid
CLKMD1
CLK/CLKS selection bit 1 (Note)
Must always be "0" 0 : Normal mode (CLK output is CLK1 only) 1 : Transfer clock output from multiple pins function selected Must always be "0"
Reserved bit
Nothing is assigned. In an attempt to write to this bit, write "0". The value, if read, turns out to be indeterminate. Note: When using multiple pins to output the transfer clock, the following requirements must be met: * UART1 internal/external clock selection bit (bit 3 at address 03A816) = "0".
Fig.GA-7 Serial I/O-related registers (5)
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 92 of 266
M16C/6KA Group
Clock synchronous serial I/O mode
(1) Clock synchronous serial I/O mode
The clock synchronous serial I/O mode uses a transfer clock to transmit and receive data. Tables.GA-2 and GA-3 list the specifications of the clock synchronous serial I/O mode. Fig.GA-8 shows the UART1 transmit/ receive mode register. Table.GA-2 Specifications of clock synchronous serial I/O mode (1) Item Specification Transfer data format * Transfer data length: 8 bits Transfer clock * When internal clock is selected (bit 3 at address 03A816 = "0" ) : fi/ 2(n+1) (Note 1) fi = f1, f8, f32 * When external clock is selected (bit 3 at address 03A816 = "1" ) : Input from CLK1 pin _______ _______ _______ _______ Transmission/reception control * Selecting from CTS function/RTS function/Disable CTS, RTS function Transmission start condition * To start transmission, the following requirements must be met: _ Transmit enable bit (bit 0 at address 03AD16) = "1" _ Transmit buffer empty flag (bit 1 at address 03AD16) = "0" _______ _______ _ When CTS function selected, CTS input level = "L" * Furthermore, if external clock is selected, the following requirements must also be met: _ CLK1 polarity select bit (bit 6 at address 03AC16) = "0": CLK1 input level = "H" _ CLK1 polarity select bit (bit 6 at address 03AC16) = "1": CLK1 input level = "L" Reception start condition * To start reception, the following requirements must be met: _ Receive enable bit (bit 2 at address 03AD16) = "1" _ Transmit enable bit (bit 0 at address 03AD16) = "1" _ Transmit buffer empty flag (bit 1 at address 03AD16) = "0" * Furthermore, if external clock is selected, the following requirements must also be met: _ CLK1 polarity select bit (bit 6 at address 03AC16) = "0": CLK1 input level = "H" _ CLK1 polarity select bit (bit 6 at address 03AC16) = "1": CLK1 input level = "L" * When transmitting _ Transmit interrupt factor selection bit (bit 1 at address 03B016) = "0": Interrupt request At the completion of data transmission from UART1 transfer buffer register generation timing to UART1 transmit register _ Transmit interrupt factor selection bit (bit 1 at address 03B016) = "1": At the completion of data transmission from UART1 transfer register is completed * When receiving _ At the completion of data transferring from UART1 receive register to UART1 receive buffer register Error detection * Overrun error (Note 2) This error occurs when bit 7 of next data is received before the contents of UART1 receive buffer register are read out. Note 1: "n" denotes the value 0016 to FF16 that is set to the UART bit rate generator. Note 2: If an overrun error occurs, the UART1 receive buffer will have the next data written in. Note also that the UART1 receive interrupt request bit is not set to "1".
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z page 93 of 266
M16C/6KA Group
Clock synchronous serial I/O mode
Table.GA-3 Specifications of clock synchronous serial I/O mode (2) Item Function selection Specification * CLK polarity selection Whether transmit data is output/input at the rising edge or falling edge of the transfer clock can be selected * LSB first/MSB first selection Whether transmission/reception begins with bit 0 or bit 7 can be selected * Continuous receive mode selection Reception is enabled simultaneously by a read from the receive buffer register * Transfer clock output from multiple pins selection UART1 transfer clock can be chosen by software to be output from one of the two pins set
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 94 of 266
M16C/6KA Group
Clock synchronous serial I/O mode
UART1 transmit/receive mode registers
b7 b6 b5 b4 b3 b2 b1 b0
001
Symbol U1MR Bit symbol SMD0 SMD1 SMD2 CKDIR STPS PRY PRYE IOPOL
Address 03A816 Bit name
When reset 0016 Function
b2 b1 b0
RW
Serial I/O mode selection bits
0 0 1 : Clock synchronous serial I/O mode 0 : Internal clock 1 : External clock (Note 1)
Internal/external clock selection bit
Invalid in clock synchronous serial I/O mode TxD, RxD I/O polarity reverse bit (Note 1) 0 : No reverse 1 : Reverse
Note 1: Usually sent to "0". Note 2: The corresponding port direction register should be "0".
Fig.GA-8 UART1 transmit/receive mode register in clock synchronous serial I/O mode
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 95 of 266
M16C/6KA Group
Clock synchronous serial I/O mode
Table.GA-4 lists the functions of the input/output pins during clock synchronous serial I/O mode. This table shows the pin functions that the transfer clock output from multiple pins are not selected. Note that for a period from when the UART1 operation mode is selected to when transfer starts, the TxD1 pin outputs a "H". (If the N-channel open-drain is selected, this pin is in floating state.) Table.GA-4 Input/output pin functions in clock synchronous serial I/O mode (The function that the transfer clock output from multiple pin is not selected.)
Pin name TxD1 RxD1 CLK1 Function Serial data output Serial data input Transfer clock output Transfer clock input CTS1/RTS1 CTS input Method of selection (Outputs dummy data when performing reception only) The corresponding bit of port direction register = "0" (Can be used as an input port when performing transmission only) Internal/external clock select bit (bit 3 at address 03A816) = "0" Internal/external clock select bit (bit 3 at address 03A816) = "1" The corresponding bit of port direction register = "0" CTS/RTS disable bit (bit 4 at address 03AC16) ="0" CTS/RTS function selection bit (bit 2 at address 03AC16) = "0" The corresponding port direction bit = "0" CTS/RTS disable bit (bit 4 at address 03AC16) = "0" CTS/RTS function selection bit (bit 2 at address 03AC16) = "1" CTS/RTS disable bit (bit 4 at address 03AC16) = "1"
RTS output Programmable I/O port
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 96 of 266
M16C/6KA Group
Clock synchronous serial I/O mode
* Example of transmit timing (when internal clock is selected)
Tc
Transfer clock
"1" "0" "1" "0" Transferred from UART1 transmit buffer register to UART1 transmit register "H" Data is set in UART1 transmit buffer register
Transmit enable bit (TE) Transmit buffer empty flag (Tl) CTS1
"L"
TCLK
Stopped because CTS = "H"
Stopped because transfer enable bit = "0"
CLK1
TxD1 Transmit register empty flag (TXEPT)
"1" "0"
D0 D1 D2 D3 D4 D5 D6 D7
D0 D1 D2 D3 D4 D5 D6 D7
D0 D1 D2 D3 D4 D5 D6 D7
Transmit interrupt "1" request bit (IR) "0"
Cleared to "0" when interrupt request is accepted, or cleared by software Shown in ( ) are bit symbols. The above timing applies to the following settings: * Internal clock is selected. * CTS function is selected. * CLK polarity selection bit = "0". * Transmit interrupt factor selection bit = "0". Tc = TCLK = 2(n + 1) / fi fi: frequency of BRG1 count source (f1, f8, f32) n: value set to BRG1
* Example of receive timing (when external clock is selected)
Receive enable bit (RE) Transmit enable bit (TE) Transmit buffer empty flag (Tl) RTS1
"1" "0" "1" "0" "1" "0" "H" "L"
Dummy data is set in UART1 transmit buffer register
Transferred from UART1 transmit buffer register to UART1 transmit register
1 / fEXT
CLK1
Receive data is taken in D0 D1 D2 D3 D4 D5 D6 D7 "1"
Transferred from UART1 receive register to UART1 receive buffer register
RxD1 Receive complete "0" flag (Rl) Receive interrupt request bit (IR)
"1" "0"
D0 D1 D2 D3 D4 D5
Read out from UART1 receive buffer register
Cleared to "0" when interrupt request is accepted, or cleared by software Shown in ( ) are bit symbols. The above timing applies to the following settings: * External clock is selected. * RTS function is selected. * CLK polarity selection bit = "0". fEXT: frequency of external clock The following conditions should be matched when the input level of CLK1 pin is "H" before the data reception. * Transmit enable bit "1" * Receive enable bit "1" * Dummy data write to UART1 transmit buffer register
Fig.GA-9 Typical transmit/receive timings in clock synchronous serial I/O mode
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 97 of 266
M16C/6KA Group
Clock synchronous serial I/O mode
(a) Polarity selection function As shown in Fig.GA-10, the CLK polarity selection bit (bit 6 at address 03AC16) allows to select the polarity of the transfer clock.
* When CLK polarity selection bit = "0"
CLK1 TXD1 RXD1 D0 D0 D1 D1 D2 D2 D3 D3 D4 D4 D5 D5 D6 D6 D7 D7
Note 1: The CLK pin level is "H" when there is no transferring.
* When CLK polarity select bit = "1"
CLK1 TXD1 RXD1 D0 D0 D1 D1 D2 D2 D3 D3 D4 D4 D5 D5 D6 D6 D7 D7
Note 2: The CLK pin level is "L" when there is no transferring.
Fig.GA-10 Polarity of transfer clock (b) LSB first/MSB first selection function As shown in Fig.GA-11, when the transfer format selection bit (bit 7 at address 03AC16) = "0", the transfer format is "LSB first"; when the bit = "1", the transfer format is "MSB first".
* When transfer format selection bit = "0"
CLK1 TXD1 RXD1 D0 D0 D1 D1 D2 D2 D3 D3 D4 D4 D5 D5 D6 D6 D7
LSB first
D7
* When transfer format selection bit = "1"
CLK1 TXD1 RXD1 D7 D7 D6 D6 D5 D5 D4 D4 D3 D3 D2 D2 D1 D1 D0
MSB first
D0
Note: This applies when the CLK polarity selection bit = "0".
Fig.GA-11 Transfer format
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 98 of 266
M16C/6KA Group
Clock synchronous serial I/O mode
(c) Transfer clock output from multiple pins function (UART1) This function allows to set two transfer clock output pins and chooses one to output a clock by the setting of CLK and CLKS selection bits (bits 4 and 5 at address 03B016). (See Fig.GA-12) The function is valid only _______ _______ when the UART1 internal clock is selected. Note that when this function is selected, CTS/RTS function cannot be used.
Microcomputer
TXD1
CLKS1 CLK1 IN CLK IN CLK
Fig.GA-12 The sample of transfer clock output from the multiple pins function
(d) Continuous receive mode If the continuous receive mode enable bit (bit 3 at address 03B016) are set to "1", the unit is placed in continuous receive mode. In this mode, when the receive buffer register is read out, the unit simultaneously goes to a receive enable state without having to set dummy data to the transmit buffer register back again.
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 99 of 266
M16C/6KA Group
Clock asynchronous serial I/O (UART) mode
(2) Clock asynchronous serial I/O (UART) mode
The UART mode allows transmitting and receiving data after setting the desired transfer rate and transfer data format. Tables.GA-5 and GA-6 list the specifications of the UART mode. Fig.GA-13 shows the UART1 transmit/receive mode register. Table.GA-5 Specifications of UART Mode (1) Item Specification Transfer data format * Character bit (transfer data): 7 bits, 8 bits, or 9 bits as selected * Start bit: 1 bit * Parity bit: Odd, even, or nothing as selected * Stop bit: 1 bit or 2 bits as selected Transfer clock * When internal clock is selected (bit 3 at address 03A816 = "0") : fi/16(n+1) (Note 1) fi = f1, f8, f32 * When external clock is selected (bit 3 at address 03A816 ="1") : fEXT/16(n+1)(Note 1) (Note 2) _______ _______ Transmission/reception control * Selecting from Disable CTS, RTS function Transmission start condition * To start transmission, the following requirements must be met: - Transmit enable bit (bit 0 at address 03AD16) = "1" - Transmit buffer empty flag (bit 1_______ at address 03AD16) = "0" _______ - When CTS function is selected CTS input level = "L" Reception start condition * To start reception, the following requirements must be met: - Receive enable bit (bit 2 at address 03AD16) = "1" - Start bit detection Interrupt request * When transmitting generation timing - Transmit interrupt factor selection bit (bit 1 at address 03B016) = "0": At the completion of data transferring from UART1 transfer buffer register to UART1 transmit register - Transmit interrupt factor selection bit (bit 1 at address 03B016) = "1": At the completion of data transmission from UART1 transfer register * When receiving - At the completion of data transferring from UART1 receive register to UART1 receive buffer register Error detection * Overrun error (Note 3) This error occurs when the bit prior to the stop bit of next data is received before the contents of UART1 receive buffer register are read out. * Framing error This error occurs when the number set for stop bits is not detected * Parity error This error occurs in the case that parity is enabled and the number of "1" in parity bit and character bits does not match the number of "1" in parity odd/ even setting. * Error sum flag This flag is set (= 1) when any of the overrun, framing, and parity errors is encountered Note 1: `n' denotes the value 0016 to FF16 that is set to the UART1 bit rate register. Note 2: fEXT is input from the CLK1 pin. Note 3: If an overrun error occurs, the UART1 receive buffer will have the next data written in. Also note that the UART1 receive interrupt request bit is not set to "1".
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 100 of 266
M16C/6KA Group
Clock asynchronous serial I/O (UART) mode
Table.GA-6 Specifications of UART Mode (2) Item Function selection Specification * Serial data logic switch This function is reversing logic value of transferring data. Start bit, and stop bit are not reversed. * TXD, RXD I/O polarity switch This function is reversing TXD port output and RXD port input. All I/O data level are reversed.
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 101 of 266
M16C/6KA Group
Clock asynchronous serial I/O (UART) mode
UART1 transmit / receive mode registers
b7 b6 b5 b4 b3 b2 b1 b0
Symbol U1MR
Address 03A816
When reset 0016
Bit symbol
SMD0 SMD1 SMD2 CKDIR STPS PRY
Bit name
Serial I/O mode selection bits
b2 b1 b0
Function
1 0 0 : Transfer data 7 bits long 1 0 1 : Transfer data 8 bits long 1 1 0 : Transfer data 9 bits long 0 : Internal clock 1 : External clock (Note 1) 0 : One stop bit 1 : Two stop bits Valid when bit 6 = "1" 0 : Odd parity 1 : Even parity 0 : Parity disabled 1 : Parity enabled 0 : No reverse 1 : Reverse
RW
Internal / external clock selection bit Stop bit length select bit Odd / even parity select bit
PRYE IOPOL
Parity enable bit TxD, RxD I/O polarity switching bit (Note 2)
Note 1: The corresponding port direction register should be "0". Note 2: Usually set to "0".
Fig.GA-13 UARTi transmit/receive mode register in UART mode
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 102 of 266
M16C/6KA Group
Clock asynchronous serial I/O (UART) mode
Table.GA-7 lists the functions of the input/output pins during UART mode. Note that for a period from when the UART1 operation mode is selected to when transfer starts, the TxD1 pin outputs a "H". (If the N-channel open-drain is selected, this pin is in floating state.) Table.GA-7 Input/output pin functions in UART mode
Pin name TXD1 RXD1 CLK1 Function Serial data output Serial data input Programmable I/O port Transfer clock input CTS1/RTS1 CTS input Corresponding port direction register bit = "0". (Can be used as an input port when performing transmission only) Internal/external clock selection bit (bit 3 at address 03A816) = "0" Internal/external clock selection bit (bit 3 at address 03A816) = "1" Corresponding port direction register bit = "0" CTS/RTS disable bit (bit 4 at address 03AC16) ="0" CTS/RTS function selection bit (bit 2 at address 03AC16) = "0" Corresponding port direction register bit = "0" CTS/RTS disable bit (bit 4 at address 03AC16) = "0" CTS/RTS function selection bit (bit 2 at address 03AC16) = "1" CTS/RTS disable bit (bit 4 at address 03AC16) = "1" Method of selection
RTS output Programmable I/O port
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 103 of 266
M16C/6KA Group
Clock asynchronous serial I/O (UART) mode
* Example of transmit timing when transfer data are 8 bits long (parity enabled, one stop bit)
Tc
Transfer clock Transmit enable bit(TE) Transmit buffer empty flag(TI)
"1" "0" "1" "0"
The transfer clock stops momentarily as CTS is "H" when the stop bit is checked. The transfer clock starts as the transfer starts immediately CTS changes to "L".
Data is set in UART1 transmit buffer register.
Transferred from UART1 transmit buffer register to UART1 transmit register
"H"
CTS1
"L"
Start bit TxD1
"1" Transmit register empty flag (TXEPT) "0" "1" "0"
Parity bit
P
Stop bit
SP
Stopped because transmit enable bit = "0"
ST D0 D1 D2 D3 D4 D5 D6 D7 P SP ST D0 D1
ST D0 D1 D2 D3 D4 D5 D6 D7
Transmit interrupt request bit (IR)
Cleared to "0" when interrupt request is accepted, or cleared by software Shown in ( ) are bit symbols. The above timing applies to the following settings : * Parity is enabled. * One stop bit. * CTS function is selected. * Transmit interrupt factor selection bit = "1". Tc = 16 (n +1) / fi or 16 (n +1) / fEXT fi : frequency of BRG1 count source (f1, f8, f32) fEXT : frequency of BRG1 count source (external clock) n : value set to BRG1
* Example of transmit timing when transfer data are 9 bits long (parity disabled, two stop bits)
Tc
Transfer clock Transmit enable bit(TE) Transmit buffer empty flag(TI)
"1" "0" "1" "0"
Data is set in UART1 transmit buffer register
Transferred from UART1 transmit buffer register to UART1 transmit register Start bit TxD1
"1" Transmit register empty flag (TXEPT) "0"
Stop bit
Stop bit
ST D0 D1 D2 D3 D4 D5 D6 D7 D8 SPSP ST D0 D1
ST D0 D1 D2 D3 D4 D5 D6 D7 D8 SP SP
Transmit interrupt request bit (IR)
"1" "0"
Cleared to "0" when interrupt request is accepted, or cleared by software Shown in ( ) are bit symbols. The above timing applies to the following settings : * Parity is disabled. * Two stop bits. * CTS function is disabled. * Transmit interrupt factor selection bit = "0". Tc = 16 (n +1) / fi or 16 (n +1) / fEXT fi : frequency of BRG1 count source (f1, f8, f32) fEXT : frequency of BRG1 count source (external clock) n : value set to BRG1
Fig.GA-14 Typical transmit timings in UART mode
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z page 104 of 266
M16C/6KA Group
Clock asynchronous serial I/O (UART) mode
* Example of receive timing when transfer data are 8 bits long (parity disabled, one stop bit)
BRG1 count source Receive enable bit RxD1 "1" "0" Start bit Sampled "L" Receive data taken in Transfer clock Receive complete flag RTS1 Receive interrupt request bit Reception triggered when transfer clock "1" is generated by falling edge of start bit "0" "H" "L" "1" "0" Transferred from UART1 receive register to UART1 receive buffer register
Stop bit
D0
D1
D7
Cleared to "0" when interrupt request is accepted, or cleared by software The above timing applies to the following settings : *Parity is disabled. *One stop bit. *RTS function is selected.
Fig.GA-15 Typical receive timing in UART mode
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 105 of 266
M16C/6KA Group
Clock asynchronous serial I/O (UART) mode
(a) Function for switching serial data logic When the data logic selection bit is assigned 1, data is inverted in writing to the transmission buffer register or reading the reception buffer register. Fig.GA-16 shows the example of timing for switching serial data logic.
* When LSB first, parity enabled, one stop bit
Transfer clock TxD1
(no reverse)
"H" "L" "H" "L" "H" "L"
ST
D0
D1
D2
D3
D4
D5
D6
D7
P
SP
TxD1
(reverse)
ST
D0
D1
D2
D3
D4
D5
D6
D7
P
SP
ST : Start bit P : Even parity SP : Stop bit
Fig.GA-16 Timing for switching serial data logic
(b) TxD, RxD I/O polarity switching function This function is to reverse TXD pin output and RXD pin input. The level of any data to be input or output (including the start bit, stop bit(s), and parity bit) is reversed. Set this function to "0" (not to reverse) for usual use.
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 106 of 266
M16C/6KA Group
SI/O3,4
S I/O3, 4
S I/O 3 and S I/O 4 are exclusive clock-synchronous serial I/Os. Fig.GA-17 shows the S I/O 3, 4 block diagram, and Fig.GA-18 shows the S I/O 3, 4 control register. Table.GA-8 shows the specifications of S I/O 3, 4.
f1 f8 f32
SMi1 SMi0
Data bus
Synchronous circuit SMi3 SMi6 SMi6
1/2
1/(ni+1)
Transfer rate register (8)
CLKi
S I/O counter i (3)
S I/Oi interrupt request
SMi2 SMi3 SMi5 LSB MSB
SOUTi SINi
S I/Oi transmission/reception register (8) 8 Note: i = 3, 4. ni = A value set in the S I/O transfer rate register i (036316, 036716).
Fig.GA-17 S I/O3, 4 block diagram
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 107 of 266
M16C/6KA Group
SI/O3,4
S I/Oi control register (i = 3, 4) (Note 1)
b7 b6 b5 b4 b3 b2 b1 b0
0 Bit symbol
SMi0 SMi1 SMi2 SMi3
Symbol SiC
Address 036216, 036616 Bit name
When reset 4016 Description
b1 b0
RW
Internal synchronous clock selection bits
0 0 : Selecting f1 0 1 : Selecting f8 1 0 : Selecting f32 1 1 : Not to be used 0 : SOUTi output 1 : SOUTi output disable (high impedance) 0 : Input-output port 1 : SOUTi output, CLK function Must be "0" 0 : LSB first 1 : MSB first 0 : External clock 1 : Internal clock Effective when SMi3 = 0 0 : L output 1 : H output
SOUTi output disable bit S I/Oi port selection bit (Note 2)
Reserved bit SMi5 SMi6 SMi7 Transfer direction selection bit Synchronous clock selection bit (Note 2) SOUTi initial value set bit
Note 1: Set "1" in bit 2 of the protection register (000A16) in advance to write to the S I/Oi control register (i = 3, 4). Note 2: When SI/Oi port selection bit (i= 3, 4) is set to "0" as for I/O port, set the synchronous clock selection bit to "1".
SI/Oi bit rate generator
b7 b0
Symbol S3BRG S4BRG
Address 036316 036716 Indeterminate
When reset Indeterminate Indeterminate Values that can be set 0016 to FF16 RW
Assuming that set value = n, BRGi divides the count source by n + 1
SI/Oi transmission/reception register
b7 b0
Symbol S3TRR S4TRR
Address 036016 036416 Indeterminate
When reset Indeterminate Indeterminate RW
Transmission/reception starts by writing data to this register. After transmission/reception finishes, reception data is input.
Fig.GA-18 S I/O3, 4 control registers
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 108 of 266
M16C/6KA Group
SI/O3,4
Table.GA-8 Specifications of S I/O3, 4 Specifications Item Transfer data format * Transfer data length: 8 bits * With the internal clock selected (bit 6 of 036216, 036616 = "1"): f1/2(ni+1), Transfer clock f8/2(ni+1), f32/2(ni+1) (Note 1) * With the external clock selected (bit 6 of 036216, 036616 = 0):Input from the CLKi terminal (Note 2) * To start transmit/reception, the following requirements must be met: Conditions for - Select the synchronous clock (use bit 6 of 036216, 036616). transmission/ Select a frequency dividing ratio if the internal clock has been selected (use bits reception start 0 and 1 of 036216, 036616). - SOUTi initial value set bit (use bit 7 of 036216, 036616)= 1. - S I/Oi port select bit (bit 3 of 036216, 036616) = 1. - Select the transfer direction (use bit 5 of 036216, 036616) - Write transfer data to SI/Oi transmission/reception register(036016, 036416) * To use S I/Oi interrupts, the following requirements must be met: - S I/Oi interrupt request bit (bit 3 of 004916, 004816) = 0. Interrupt request * At the rising edge of the last transfer clock (Note3) generation timing Select function * LSB first or MSB first selection Whether transmission/reception begins with bit 0 (LSB) or bit 7 (MSB) can be selected. * The SOUTi default value setting function If the transfer clock is selected to external clock, the output level of SOUTi pin can be selected when it is not in transferring please refer to Fig.GA-30. * The SI/Oi (i=3,4) is different from UART0 to 2 that the register and buffer can not be separated, so don't write the next transfer data to the transmission/reception register(036016, 036416) during transferring. * If the transfer clock is selected to internal clock, at the end of transferring, the SOUTi holds the last data during the last 1/2 transfer clock, and then to high impedance. If the transmission/reception register(036016, 036416) is written during the period, the SOUTi becomes the high impedance right the writing, the data hold time will be shortened.
Precaution
Note 1: n is a value from 0016 through FF16 set in the S I/Oi transfer rate register (i = 3, 4). Note 2: With the external clock selected: * Please write to the SI/Oi transmission/reception register(036016, 036416) under the status that the CLKi pin is input to "H" level. Also please write to the bit 7(SOUTi default value setting bit) under the status that the CLKi pin is input to "H" level. * The S I/Oi circuit keeps on with the shift operation as long as the synchronous clock is entered in it, so stop the synchronous clock at the instant when it counts to eight. The internal clock, if selected, automatically stops. Note 3: If the internal clock is used for the synchronous clock, the transfer clock signal stops at the "H" state.
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 109 of 266
M16C/6KA Group
SI/O3,4
Functions for setting an SOUTi initial value
In carrying out transmission, the output level of the SOUTi pin as it is before transmitting 1-bit data can be set either to "H" or to "L". Fig.GA-19 shows the timing chart for setting an SOUTi initial value and how to set it.
(Example) With "H" selected for SOUTi
Signal written to the SI/Oi transmission /reception register SOUTi's initial value set bit (SMi7)
SI/Oi port selection bit SMi3 = 0
SOUTi initial value selection bit SMi7 = 1 "H" level) (SOUTi: Internal
SI/Oi port selection bit (SMi3)
SOUTi (internal)
D0
SI/Oi port selection bit SMi3 = 0 1 (Port selection: Normal port SOUTi)
SOUTi pin = "H" output
Port output SOUTi pin output
D0
Initial value = "H"(Note)
Signal written to the SI/Oi register ="L" "H" "L" (Falling edge )
(i = 3, 4)
Setting the SOUTi initial value to H
Port selection (normal port SOUTi)
Note: The set value is output only when the external clock has been selected. Please set the SOUTi default under the status that the CLKi is input to "H" level. If the internal clock has been selected or if SOUTi output inhibition has been set, this output goes to the high-impedance state.
SOUTi pin = Outputting stored data in the SI/Oi transmission/ reception register
Fig.GA-19 Timing chart for setting SOUTi's initial value and how to set it
S I/Oi operation timing
Fig.GA-20 shows the S I/Oi operation timing
MAX:1.5 cycle SI/Oi internal clock Transfer clock (Note 1) Signal written to the SI/Oi register (Note 2) S I/Oi output SOUTi (i= 3, 4) SI/Oi input SINi (i= 3, 4) SI/Oi interrupt "1" request bit (i=3,4) "0" Note 1: With the internal clock selected for the transfer clock, the frequency dividing ratio can be selected using bits 0 and 1 of the SI/Oi control register (i = 3,4). (No frequency division, 8-division frequency, 32-division frequency.) Note 2: With the internal clock selected for the transfer clock, the SOUTi (i = 3,4) pin becomes to the high-impedance state after the transfer finishes. Note 3: The figure shows when the port selection bit of SOUTi (i = 3,4) is set to "1". Hiz D0 D1 D2 D3 D4 D5 D6 D7 Hiz
Fig.GA-20 S I/Oi operation timing chart
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 110 of 266
M16C/6KA Group
A-D Converter
A-D Converter
The A-D converter consists of one 10-bit successive approximation A-D converter circuit with a capacitive coupling amplifier. Pins P100 to P107, P95, and P96 also function as the analog signal input pins. The direction registers of these pins for A-D conversion must therefore be set to input. The Vref connect bit (bit 5 at address 03D716) can be used to isolate the resistance ladder of the A-D converter from the reference voltage input pin (VREF) when the A-D converter is not used. Doing so stops any current flowing into the resistance ladder from VREF, reducing the power dissipation. When using the A-D converter, start A-D conversion only after setting bit 5 of 03D716 to connect VREF. The result of A-D conversion is stored in the A-D registers of the selected pins. When set to 10-bit precision, the low 8 bits are stored in the even addresses and the high 2 bits in the odd addresses. When set to 8-bit precision, the low 8 bits are stored in the even addresses. Table.JA-1 shows the performance of the A-D converter. Fig.JA-1 shows the block diagram of the A-D converter, and Fig.JA-2 and JA-3 show the A-D converter-related registers. Table.JA-1 Performance of A-D converter Item Performance Method of A-D conversion Successive approximation (capacitive coupling amplifier) Analog input voltage 0V to AVCC (VCC) Operating clockAD (Note1) fAD/divide-by-2 of fAD/divide-by-4 of fAD, fAD=f(XIN) Resolution 8-bit or 10-bit (selectable) Absolute precision * 8-bit resolution 2LSB * 10-bit resolution 6LSB Operating modes One-shot mode, repeat mode, single sweep mode, repeat sweep mode 0, and repeat sweep mode 1 Analog input pins 8pins (AN0 to AN7) + 2pins (ANEX0 and ANEX1) A-D conversion start condition * Software trigger A-D conversion starts when the A-D conversion start flag changes to "1" * External trigger (can be retriggered) A-D conversion starts when the A-D conversion start flag is "1" and the ___________ ADTRG/P97 input changes from "H" to "L" Conversion speed per pin * Without sample and hold function 8-bit resolution : 49 AD cycles 10-bit resolution : 59 AD cycles * With sample and hold function 8-bit resolution : 28 AD cycles 10-bit resolution : 33 AD cycles Note 1: The frequency AD should be set to 250kHz min and 8MHz max. Without sample and hold function,set the AD frequency to 250kHz min. With the sample and hold fucntion, set the AD frequency to 1MHz min.
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 111 of 266
M16C/6KA Group
A-D Converter
A-D conversion rate selection
CKS1=1
AD
CKS0=1
fAD
1/2
1/2
CKS0=0
CKS1=0
VREF
VCUT=0
Resistor ladder
AVSS
VCUT=1
Successive conversion register A-D control register 1 (address 03D716)
A-D control register 0 (address 03D616)
Addresses
(03C116, 03C016) (03C316, 03C216) (03C516, 03C416) (03C716, 03C616) (03C916, 03C816) (03CB16, 03CA16) (03CD16, 03CC16) (03CF16, 03CE16)
A-D register 0(16) A-D register 1(16) A-D register 2(16) A-D register 3(16) A-D register 4(16) A-D register 5(16) A-D register 6(16) A-D register 7(16) Vref Decoder
VIN
Comparator
Data bus high-order
Data bus low-order
AN0 AN1 AN2 AN3 AN4 AN5 AN6 AN7
CH2,CH1,CH0=000 CH2,CH1,CH0=001 CH2,CH1,CH0=010 CH2,CH1,CH0=011 CH2,CH1,CH0=100 CH2,CH1,CH0=101 CH2,CH1,CH0=110 CH2,CH1,CH0=111
OPA1, OPA0
OPA1,OPA0=0,0
OPA1,OPA0=0,1
ANEX0 ANEX1
OPA1,OPA0=1,0
0 0 1 1
0 : AN0-AN7 1 : ANEX0 0 : ANEX1 1 : Inhibited
Fig.JA-1 Block diagram of A-D converter
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z page 112 of 266
M16C/6KA Group
A-D Converter
A-D control register 0 (Note 1)
b7 b6 b5 b4 b3 b2 b1 b0
Symbol ADCON0 Bit symbol
CH0 CH1
Address 03D616 Bit name
When reset 00000XXX2 Function
b2 b1 b0
RW
Analog input pin selection bits
CH2 MD0 MD1 TRG ADST CKS0 Trigger selection bit A-D conversion start flag Frequency selection bit 0 A-D operation mode selection bits 0
0 0 0 : AN0 is selected 0 0 1 : AN1 is selected 0 1 0 : AN2 is selected 0 1 1 : AN3 is selected 1 0 0 : AN4 is selected 1 0 1 : AN5 is selected 1 1 0 : AN6 is selected 1 1 1 : AN7 is selected
b4 b3
(Note 2)
0 0 : One-shot mode 0 1 : Repeat mode 1 0 : Single sweep mode 1 1 : Repeat sweep mode 0 Repeat sweep mode 1 0 : Software trigger 1 : ADTRG trigger 0 : A-D conversion disabled 1 : A-D conversion started
(Note 2)
0 : FAD/4 selected 1 : FAD/2 selected Note 1: If the A-D control register is rewritten during A-D conversion, the conversion result is indeterminate. Note 2: When changing A-D operation mode, set analog input pin again.
A-D control register 1 (Note)
b7 b6 b5 b4 b3 b2 b1 b0
Symbol ADCON1 Bit symbol
SCAN0
Address 03D716 Bit name
When reset 0016 Function RW
A-D sweep pin selection bits When single sweep and repeat sweep mode 0 are selected
b1 b0
0 0 : AN0, AN1 (2 pins) 0 1 : AN0 to AN3 (4 pins) 1 0 : AN0 to AN5 (6 pins) 1 1 : AN0 to AN7 (8 pins) SCAN1 When repeat sweep mode 1 is selected
b1 b0
0 0 : AN0 (1 pin) 0 1 : AN0, AN1 (2 pins) 1 0 : AN0 to AN2 (3 pins) 1 1 : AN0 to AN3 (4 pins) MD2 A-D operation mode selection bit 1 8/10-bit mode selection bit 0 : Any mode other than repeat sweep mode 1 1 : Repeat sweep mode 1 0 : 8-bit mode 1 : 10-bit mode 0 : FAD/2 or FAD/4 selected 1 : FAD selected 0 : Vref not connected 1 : Vref connected
b7 b6
BITS CKS1 VCUT OPA0
Frequency selection bit 1 Vref connect bit
ANEX0,1 selection bits OPA1
0 0 : ANEX0 and ANEX1 are not used 0 1 : ANEX0 input is A-D converted 1 0 : ANEX1 input is A-D converted 1 1 : Inhibited
Note: If the A-D control register is rewritten during A-D conversion, the conversion result is indeterminate.
Fig.JA-2 A-D converter-related registers (1)
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z page 113 of 266
M16C/6KA Group
A-D Converter
A-D control register 2 (Note)
b7 b6 b5 b4 b3 b2 b1 b0
0000
Symbol ADCON2 Bit symbol
SMP
Address 03D416 Bit name
When reset 000100002 Function
0 : Without sample and hold 1 : With sample and hold Must be "0". RW
A-D conversion method select bit
Reserved bits Nothing is assigned.
In an attempt to write to this bit, write "0". The value, if read, turn out to be "0".
A-D register i
(b15) b7 (b8) b0 b7
Symbol
ADi(i=0 to 7)
Address When reset 03C016 to 03CF16 Indeterminate
b0
Function
Eight low-order bits of A-D conversion result * During 10-bit mode Two high-order bits of A-D conversion result * During 8-bit mode When read, the content is indeterminate Nothing is assigned. In an attempt to write to these bits, write "0". The value, if read, turns out to be "0".
RW
Fig.JA-3 A-D converter-related registers (2)
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 114 of 266
M16C/6KA Group
A-D Converter
(1) One-shot mode
In one-shot mode, the pin selected using the analog input pin selection bits is used for one-shot A-D conversion. Table.JA-2 shows the specifications of one-shot mode. Fig.JA-4 shows the A-D control register in oneshot mode. Table.JA-2 One-shot mode specifications Item Specification Function The pin selected by the analog input pin selection bits is used for one A-D conversion Start condition Writing "1" to A-D conversion start flag Stop condition * End of A-D conversion (A-D conversion start flag changes to "0", except when external trigger is selected) * Writing "0" to A-D conversion start flag Interrupt request generation timing End of A-D conversion Input pin One of AN0 to AN7, as selected Reading of result of A-D converter Read A-D register corresponding to selected pin
A-D control register 0 (Note 1)
b7 b6 b5 b4 b3 b2 b1 b0
00
Symbol ADCON0 Bit symbol
CH0 CH1
Address 03D616 Bit name
When reset 00000XXX2 Function
b2 b1 b0
RW
Analog input pin selection bits
CH2 MD0 MD1 TRG ADST CKS0 A-D operation mode selection bits 0 Trigger selection bit A-D conversion start flag Frequency selection bit 0
0 0 0 : AN0 is selected 0 0 1 : AN1 is selected 0 1 0 : AN2 is selected 0 1 1 : AN3 is selected 1 0 0 : AN4 is selected 1 0 1 : AN5 is selected 1 1 0 : AN6 is selected 1 1 1 : AN7 is selected
b4 b3
(Note 2) (Note 2)
0 0 : One-shot mode 0 : Software trigger 1 : ADTRG trigger 0 : A-D conversion disabled 1 : A-D conversion started 0 : FAD/4 selected 1 : FAD/2 selected
Note 1: If the A-D control register is rewritten during A-D conversion, the conversion result is indeterminate. Note 2: When changing A-D operation mode, set analog input pin again.
A-D control register 1 (Note)
b7 b6 b5 b4 b3 b2 b1 b0
1
0
Symbol ADCON1 Bit symbol
SCAN0 SCAN1 MD2 BITS CKS1 VCUT OPA0
Address 03D716 Bit name
When reset 0016 Function RW
A-D sweep pin selection Invalid in one-shot mode bits A-D operation mode selection bit 1 8/10-bit mode select bit 0 : Any mode other than repeat sweep mode 1
0 : 8-bit mode 1 : 10-bit mode 0 : FAD/2 or FAD/4 selected Frequency selection bit 1 1 : FAD selected Vref connect bit 1 : Vref connected
b7 b6
ANEX0,1 selection bis OPA1
0 0 : ANEX0 and ANEX1 are not used 0 1 : ANEX0 input is A-D converted 1 0 : ANEX1 input is A-D converted 1 1 : Inhibited
Note: If the A-D control register is rewritten during A-D conversion, the conversion result is indeterminate.
Fig.JA-4 A-D conversion register in one-shot mode
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 115 of 266
M16C/6KA Group
A-D Converter
(2) Repeat mode
In repeat mode, the pin selected using the analog input pin selection bits is used for repeated A-D conversion. Table.JA-3 shows the specifications of repeat mode. Fig.JA-5 shows the A-D control register in repeat mode. Table.JA-3 Repeat mode specifications Item Function Star condition Stop condition Interrupt request generation timing Input pin Reading of result of A-D converter Specification The pin selected by the analog input pin selection bits is used for repeated A-D conversion Writing "1" to A-D conversion start flag Writing "0" to A-D conversion start flag Not generated One of AN0 to AN7, as selected Read A-D register corresponding to selected pin
A-D control register 0 (Note 1)
b7 b6 b5 b4 b3 b2 b1 b0
01
Symbol ADCON0 Bit symbol
CH0 CH1
Address 03D616 Bit name
When reset 00000XXX2 Function
b2 b1 b0
RW
CH2 MD0 MD1 TRG ADST CKS0
Analog input pin selection 0 0 0 : AN0 is selected bits 0 0 1 : AN1 is selected 0 1 0 : AN2 is selected 0 1 1 : AN3 is selected 1 0 0 : AN4 is selected 1 0 1 : AN5 is selected 1 1 0 : AN6 is selected 1 1 1 : AN7 is selected A-D operation mode selection bits 0 Trigger selection bit A-D conversion start flag Frequency selection bit 0
b4 b3
(Note 2) (Note 2)
0 1 : Repeat mode 0 : Software trigger 1 : ADTRG trigger 0 : A-D conversion disabled 1 : A-D conversion started 0 : FAD/4 selected 1 : FAD/2 selected
Note 1: If the A-D control register is rewritten during A-D conversion, the conversion result is indeterminate. Note 2: When changing A-D operation mode, set analog input pin again.
A-D control register 1 (Note)
b7 b6 b5 b4 b3 b2 b1 b0
1
0
Symbol ADCON1 Bit symbol
SCAN0 SCAN1 MD2 BITS CKS1 VCUT OPA0
Address 03D716 Bit name
When reset 0016 Function
Invalid in repeat mode RW
A-D sweep pin selection bits A-D operation mode selection bit 1 8/10-bit mode selection bit
Should be "0" in this mode
0 : 8-bit mode 1 : 10-bit mode 0 : FAD/2 or FAD/4 selected Frequency selection bit 1 1 : FAD selected 1 : Vref connected
b7 b6
Vref connect bit
ANEX0,1 selection bis OPA1
0 0 : ANEX0 and ANEX1 are not used 0 1 : ANEX0 input is A-D converted 1 0 : ANEX1 input is A-D converted 1 1 : Inhibited
Note: If the A-D control register is rewritten during A-D conversion, the conversion result is indeterminate.
Fig.JA-5 A-D conversion register in repeat mode
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 116 of 266
M16C/6KA Group
A-D Converter
(3) Single sweep mode
In single sweep mode, the pins selected using the A-D sweep pin selection bits are used for one-by-one AD conversion. Table.JA-4 shows the specifications of single sweep mode. Fig.JA-6 shows the A-D control register in single sweep mode. Table.JA-4 Single sweep mode specifications Item Specification Function The pins selected by the A-D sweep pin selection bits are used for one-by-one A-D conversion Start condition Writing "1" to A-D converter start flag Stop condition * End of A-D conversion (A-D conversion start flag changes to "0", except when external trigger is selected) * Writing "0" to A-D conversion start flag Interrupt request generation timing End of A-D conversion Input pin AN0 and AN1 (2 pins), AN0 to AN3 (4 pins), AN0 to AN5 (6 pins), or AN0 to AN7 (8 pins) Reading of result of A-D converter Read A-D registers corresponding to selected pins
A-D control register 0 (Note)
b7 b6 b5 b4 b3 b2 b1 b0
10
Symbol ADCON0 Bit symbol
CH0 CH1 CH2 MD0 MD1 TRG ADST CKS0
Address 03D616 Bit name
When reset 00000XXX2 Function
Invalid in single sweep mode
RW
Analog input pin selection bits
A-D operation mode selection bits 0 Trigger selection bit A-D conversion start flag Frequency selection bit 0
b4 b3
1 0 : Single sweep mode 0 : Software trigger 1 : ADTRG trigger 0 : A-D conversion disabled 1 : A-D conversion started 0 : FAD/4 selected 1 : FAD/2 selected
Note: If the A-D control register is rewritten during A-D conversion, the conversion result is indeterminate.
A-D control register 1 (Note 1)
b7 b6 b5 b4 b3 b2 b1 b0
1
0
Symbol ADCON1 Bit symbol
SCAN0
Address 03D716 Bit name
When reset 0016 Function
When single sweep and repeat sweep mode 0 are selected 0 0 : AN0, AN1 (2 pins) 0 1 : AN0 to AN3 (4 pins) 1 0 : AN0 to AN5 (6 pins) 1 1 : AN0 to AN7 (8 pins)
b1 b0
RW
A-D sweep pin select bit
SCAN1 A-D operation mode select bit 1 8/10-bit mode select bit
MD2 BITS CKS1 VCUT OPA0 OPA1
Should be "0" in this mode 0 : 8-bit mode 1 : 10-bit mode
Frequency selection bit 1 0 : FAD/2 or FAD/4 selected 1 : FAD selected Vref connect bit ANEX0,1 selection bis 1 : Vref connected
b7 b6
0 0 : ANEX0 and ANEX1 are not used 0 1 : ANEX0 input is A-D converted 1 0 : ANEX1 input is A-D converted 1 1 : Inhibited
Note 1: If the A-D control register is rewritten during A-D conversion, the conversion result is indeterminate.
Fig.JA-6 A-D conversion register in single sweep mode
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z page 117 of 266
M16C/6KA Group
A-D Converter
(4) Repeat sweep mode 0
In repeat sweep mode 0, the pins selected using the A-D sweep pin selection bits are used for repeat sweep A-D conversion. Table.JA-5 shows the specifications of repeat sweep mode 0. Fig.JA-7 shows the A-D control register in repeat sweep mode 0. Table.JA-5 Repeat sweep mode 0 specifications Item Function Start condition Stop condition Interrupt request generation timing Input pin Reading of result of A-D converter Specification The pins selected by the A-D sweep pin selection bits are used for repeat sweep A-D conversion Writing "1" to A-D conversion start flag Writing "0" to A-D conversion start flag Not generated AN0 and AN1 (2 pins), AN0 to AN3 (4 pins), AN0 to AN5 (6 pins), or AN0 to AN7 (8 pins) Read A-D registers corresponding to selected pins (at any time)
A-D control register 0 (Note)
b7 b6 b5 b4 b3 b2 b1 b0
11
Symbol ADCON0 Bit symbol
CH0 CH1 CH2 MD0 MD1 TRG ADST CKS0
Address 03D616 Bit name
When reset 00000XXX2 Function RW
Analog input pin selection bits Invalid in repeat sweep mode 0
A-D operation mode selection 1 1 : Repeat sweep mode 0 bits 0 Trigger selection bit A-D conversion start flag Frequency selection bit 0 0 : Software trigger 1 : ADTRG trigger 0 : A-D conversion disabled 1 : A-D conversion started 0 : FAD/4 selected 1 : FAD/2 selected
b4 b3
Note: If the A-D control register is rewritten during A-D conversion, the conversion result is indeterminate.
A-D control register 1 (Note 1)
b7 b6 b5 b4 b3 b2 b1 b0
1
0
Symbol ADCON1 Bit symbol
SCAN0
Address 03D716 Bit name
When reset 0016 Function
b1 b0
RW
A-D sweep pin selection bits When single sweep and repeat sweep mode 0 are selected 0 0 : AN0, AN1 (2 pins) 0 1 : AN0 to AN3 (4 pins) 1 0 : AN0 to AN5 (6 pins) 1 1 : AN0 to AN7 (8 pins) A-D operation mode selection bits 1 8/10-bit mode selection bit Frequency selection bit 1 Vref connect bit Should be "0" in this mode 0 : 8-bit mode 1 : 10-bit mode 0 : FAD/2 or FAD/4 selected 1 : FAD selected 1 : Vref connected
b7 b6
SCAN1
MD2 BITS CKS1 VCUT OPA0
ANEX0,1 selection bis OPA1
0 0 : ANEX0 and ANEX1 are not used 0 1 : ANEX0 input is A-D converted 1 0 : ANEX1 input is A-D converted 1 1 : Inhibited
Note 1: If the A-D control register is rewritten during A-D conversion, the conversion result is indeterminate.
Fig.JA-7 A-D conversion register in repeat sweep mode 0
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z page 118 of 266
M16C/6KA Group
A-D Converter
(5) Repeat sweep mode 1
In repeat sweep mode 1, all pins are used for A-D conversion with emphasis on the pin or pins selected using the A-D sweep pin selection bits. Table.JA-6 shows the specifications of repeat sweep mode 1. Fig.JA-8 shows the A-D control register in repeat sweep mode 1. Table.JA-6 Repeat sweep mode 1 specifications Item Function Specification All pins perform repeat sweep A-D conversion, with emphasis on the pin or pins selected by the A-D sweep pin selection bits Example : AN0 selected AN0 AN1 AN0 AN2 AN0 AN3, etc Writing "1" to A-D conversion start flag Writing "0" to A-D conversion start flag Not generated AN0 (1 pin), AN0 and AN1 (2 pins), AN0 to AN2 (3 pins), AN0 to AN3 (4 pins) Read A-D registers corresponding to selected pins (at any time)
Start condition Stop condition Interrupt request generation timing Input pin Reading of result of A-D converter
A-D control register 0 (Note)
b7 b6 b5 b4 b3 b2 b1 b0
11
Symbol ADCON0 Bit symbol
CH0 CH1 CH2 MD0 MD1 TRG ADST CKS0
Address 03D616 Bit name
When reset 00000XXX2 Function RW
Analog input pin selection bits Invalid in repeat sweep mode 1
A-D operation mode selection 1 1 : Repeat sweep mode 1 bits 0 Trigger select bit A-D conversion start flag Frequency selection bit 0 0 : Software trigger 1 : ADTRG trigger 0 : A-D conversion disabled 1 : A-D conversion started 0 : FAD/4 selected 1 : FAD/2 selected
b4 b3
Note: If the A-D control register is rewritten during A-D conversion, the conversion result is indeterminate.
A-D control register 1 (Note 1)
b7 b6 b5 b4 b3 b2 b1 b0
1
1
Symbol ADCON1 Bit symbol
SCAN0
Address 03D716 Bit name
When reset 0016 Function
When repeat sweep mode 1 is selected
b1 b0
RW
A-D sweep pin selection bits
SCAN1
0 0 : AN0 (1 pin) 0 1 : AN0, AN1 (2 pins) 1 0 : AN0 to AN2 (3 pins) 1 1 : AN0 to AN3 (4 pins) A-D operation mode selection 1 : Repeat sweep mode 1 bit 1 0 : 8-bit mode 8/10-bit mode selection bit 1 : 10-bit mode Frequency selection bit 1 Vref connect bit 0 : FAD/2 or FAD/4 selected 1 : FAD selected 1 : Vref connected
b7 b6
MD2 BITS CKS1 VCUT OPA0
ANEX0,1 selection bis OPA1
0 0 : ANEX0 and ANEX1 are not used 0 1 : ANEX0 input is A-D converted 1 0 : ANEX1 input is A-D converted 1 1 : Inhibited
Note 1: If the A-D control register is rewritten during A-D conversion, the conversion result is indeterminate.
Fig.JA-8 A-D conversion register in repeat sweep mode 1
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z page 119 of 266
M16C/6KA Group
A-D Converter
(a) Extended analog input pins
In one-shot mode and repeat mode, the input via the extended analog input pins ANEX0 and ANEX1 can also be converted from analog to digital. When bit 6 of the A-D control register 1 (address 03D716) is "1" and bit 7 is "0", input via ANEX0 is converted from analog to digital. The result of conversion is stored in A-D register 0. When bit 6 of the A-D control register 1 (address 03D716) is "0" and bit 7 is "1", input via ANEX1 is converted from analog to digital. The result of conversion is stored in A-D register 1.
(b) Sample and hold
Sample and hold is selected by setting bit 0 of the A-D control register 2 (address 03D416) to "1". When sample and hold is selected, the rage of conversion of each pin increases. As a result, a 28 AD cycle is achieved with 8-bit resolution and 33AD cycle with 10-bit resolution. Sample and hold can be selected in all modes. However, in all modes, be sure to specify before starting A-D conversion whether sample and hold is to be used.
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 120 of 266
M16C/6KA Group
PWM
PWM output circuit (PWM : Pulse Width Modulation)
There are 6 PWM output circuits, PWM0 to PWM5, with 8-bit resolution and operating independently. The input clock f(PC) for PWM is based on XIN, 2 division of XIN or 4 division of XIN.
Data bus
PWM0 prescaler pre-latch
PWM0 register pre-latch
Transmission control circuit
PWM0 prescaler latch f(XIN) 1/2 1/4 "00" "01" "10" Count source selection bits f(PC) PWM0 prescaler
PWM0 register latch P44 latch P44/PWM01 PWM0 register PWM0
PWM0 output pin selection bit PWM0 output enable bit P44 direction register
P93 latch P93/DA1/PWM00
PWM0 output pin selection bit PWM0 output enable bit Note: Refer to page 24 for the addresses of PWM prescaler and PWM register. P93 direction register
Fig.LA-1 PWM circuit (PWM0)
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 121 of 266
M16C/6KA Group
PWM
Data Setup (PWM0)
PWM0 output pin shares with P93 or P44. PWM0 output pin is selected from either P93/PWM00 or P44/ PWM01 by bit 0 of PWM control register 0 (address 030C16). PWM0 output is enabled and starts to operate by setting bit 0 of PWM control register 1 (address 030D16) to "1". The period of PWM is set by PWM0 prescaler (address 030016), The "H" width of output pulse is set by PWM0 register (address 030116). The following are the calculations if the prescaler value is n and PWM0 register value is m. (n = 0 to 255, m = 0 to 255) PWM period = 255 (n+1) = 31.875 (n+1) s f(XIN) (In the case of f(XIN)=8MHz, PWM counter source selection bits="002")
"H" width of output pulse = PWM period m = 0.125 (n+1) ms 255 (In the case of f(XIN)=8MHz, PWM counter source selection bits="002")
The setting of PWM1 to PWM5 are the same.
PWM Operation
By setting bit 0 ( PWM0 output enable bit) of PWM control register 1 to "1", the PWM output circuit starts to operate from default state with "H" pulse output. If the values of PWM0 register and PWM0 prescaler are modified during the PWM output operation, the corresponding pulse will be output from the next period after the modification.
31.875 m (n+1) 255 < >
s
PWM0 output < T = [31.875 (n+1)] s > m : The content of PWM0 register n : The content of PWM0 prescaler T : PWM Period ( in the case of f(XIN) = 8MHz)
Fig.LA-2 The timing of PWM period (PWM0)
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 122 of 266
M16C/6KA Group
PWM
A PWM0 output T The write signal to PWM0 register The write signal to PWM0 prescaler
B
C
B C = T T2
T
T2
( The modification of "H" width from "A" to "B")
( The modification of PWM period from "T" to "T2")
In the case that values of PWM0 register and PWM0 prescaler are modified, the PWM0 output will be changed from the next period after the modification.
Fig.LA-3 The PWM output timing in the case of modification of PWM register and PWM prescaler (PWM0)
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 123 of 266
M16C/6KA Group
PWM
PWM control register 0
b7 b6 b5 b4 b3 b2 b1 b0
Symbol PWMCON0
Address 030C16
When reset 0016
Bit symbol
PWMSEL0 PWMSEL1 PWMSEL2 PWMSEL3 PWMSEL4
Bit name
PWM0 output pin selection bit PWM1 output pin selection bit PWM2 output pin selection bit PWM3 output pin selection bit PWM4 output pin selection bit
Function
0 : P93/PWM00 1 : P44/PWM01 0 : P94/PWM10 1 : P45/PWM11 0 : P95/PWM20 1 : P46/PWM21 0 : P96/PWM30 1 : P47/PWM31 0 : P160/PWM40 1 : P40/PWM41 0 : P161/PWM50 1 : P41/PWM51
b7 b6
RW
PWMSEL5 PWM5 output pin selection bit
PWMCLK0 PWM count source selection bits 0 0 : f(XIN) 0 1 : f(XIN)/2 1 0 : f(XIN)/4 PWMCLK1 1 1 : Inhibit
PWM control register 1
b7 b6 b5 b4 b3 b2 b1 b0
Symbol PWMCON1
Address 030D16
When reset 0016
Bit symbol
PWMEN0 PWMEN1 PWMEN2 PWMEN3 PWMEN4 PWMEN5
Bit name
PWM0 output enable bit PWM1 output enable bit PWM2 output enable bit PWM3 output enable bit PWM4 output enable bit PWM5 output enable bit 0 : Inhibit 1 : Enable 0 : Inhibit 1 : Enable 0 : Inhibit 1 : Enable 0 : Inhibit 1 : Enable 0 : Inhibit 1 : Enable 0 : Inhibit 1 : Enable
Function
RW
Nothing is assigned. Can not be written. The value is "0" in reading.
Fig.LA-4 PWM control registers
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 124 of 266
M16C/6KA Group
LPC Bus Interface
LPC Bus Interface
LPC bus interface is based on Intel Low Pin Count (LPC) Interface Specification, Revision 1.0. It is I/O cycle data transfer format of serial communication. 4 channels are built in. The function of data bus buffer and data bus buffer status are almost the same as that of MELPS8-41 series. It can be written in or read out (as slave mode) by the control signals from host CPU side. The LPC bus interface functionality block diagram is shown in Figure GF-2. LPC data bus buffer functional Input / Output ports (P30-P36 ) are shared with GPIO port. The setting of bit3 (LPC bus buffer enable bit) of LPC control register ( address 02D616 ) is as below: 0: General purpose Input / Output port 1: LPC bus buffer functional Input / Output port The enabling of channel of LPC bus buffer is controlled by bits 4-7 (LPC bus buffer 0-3 enable bits) of LPC control register (address 02D616 ). The slave address (16 bits) of LPC bus buffer channel 0 is fixed on 0060h, 0064h. The slave addresses (16 bits) of LPC bus buffer channel 1-3 are definable by setting LPC 1-3 address register H, L (address 02D016 to 02D516 ). The setting value of bit2 of LPC1-3 address register (A2) L will not be decoded. The bit is "0" when read from slave CPU. The A2 status of slave address is latched to XA2 flag when written by host CPU. The input buffer full interrupt is generated when written in the data by host CPU. The Output buffer empty interrupt is generated when read out the data by host CPU.
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 125 of 266
M16C/6KA Group
LPC Bus Interface
Input buffer full flag0 IBF0
Rising edge detection circuit
One shot pulse generator
Input Buffer Full0 interrupt requestsignal (IBF0 interrupt request)
Input buffer full flag1 IBF1
Rising edge detection circuit
One shot pulse generator
Input Buffer Full1 interrupt request signal (IBF1 interrupt request)
Input buffer full flag2 IBF2
Rising edge detection circuit
One shot pulse generator
Input Buffer Full2 interrupt request signal (IBF2 interrupt request)
Input buffer full flag3 IBF3
Rising edge detection circuit
One shot pulse generator
Input Buffer Full3 interrupt request signal (IBF3 interrupt request)
Output buffer full flag0 OBF0
OBE0
Rising edge detection circuit Rising edge detection circuit Rising edge detection circuit Rising edge detection circuit
One shot pulse generator One shot pulse generator One shot pulse generator One shot pulse generator
Output Buffer empty interrupt request signal (OBE interrupt request)
OBE1 Output buffer full flag1 OBF1 OBE2
Output buffer full flag2 OBF2
Output buffer full flag3 OBF3
OBE3
IBF0 IBF0 interrupt request IBF1 IBF1 interrupt request IBF2 IBF2 interrupt request IBF3 IBF3 interrupt request
OBF0(OBE0) OBF1(OBE1) OBF2(OBE2) OBF3(OBE3) OBE interrupt request
Fig.GF-1 Interrupt, request, circuit of Data Bus Buffer
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 126 of 266
M16C/6KA Group
LPC Bus Interface
P34/LFRAME P35/LRESET P36/LCLK
Address register HH (Note1)
Address register HL (Note1)
Address register LH (Note1)
Input Data Comparator
P30/LAD0
P31/LAD1 Input Control Circuit
Address register LL (Note1)
RD/WR register
Start register
P32/LAD2
Input Data Buffer [7:4] Input Data Buffer [3:0]
Output Data Buffer [7:4]Output Data Buffer [3:0]
P33/LAD3 Data bus buffer status register U7 U6 U5 U4 XA2 U2 IBF OBF
Output Control Circuit
SYNC register
TAR register
Interrupt generate Circuit
Interrupt signal IBF, OBE
b7
b6
b5
b4
b3
b2
0
0
LPC control register (address 02D616)
Note1 : LPC bus interface channel 0 is fixed on slave address "0060h", "0064h".
Fig.GF-2 LPC bus interface function block diagram (LPC1)
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z page 127 of 266
Internal Data Bus
System Bus
M16C/6KA Group
LPC Bus Interface
Figure GF-3: Data bus buffer control registers Figure GF-4: Data bus buffer status register Figure GF-5, 6: LPC related registers
Data bus buffer status register (DBBSTS0-DBBSTS3)
This is 8-bit register. The bit 0, 1, 3 are read only bits and indicate the status of data bus buffer. Bit 2, 4, 5, 6, 7 are user definable and flags which can be read and written by software. The data bus buffer status register can be read out by host CPU when the slave address (16 bit) bit2 (A2) is high. * Output buffer full flag (OBF) The bit will be set to "1" when a data is written into output data bus buffer and will be cleared to "0" when host CPU read out the data from output data bus buffer. * Input buffer full flag (IBF) The bit will be set to "1" while a data is written into input data bus buffer by host CPU and will be cleared to "0" when the data is read out from input data bus buffer by slave CPU. * XA2 flag (XA2) The bit 2 of slave address (16 bits) is latched while a data is written into data bus buffer.
Input data bus buffer register (DBBIN0-DBBIN3)
When there is a write request from host CPU, the data on the data bus will be latched to DBBIN0-3. The data of DBBIN0-3 can be read out from data bus buffer registers (Address:02C016, 02C216 , 02C416 , 02C616 ) in SFR field.
Output data bus buffer register (DBBOUT0-DBBOUT3)
When writing data to data bus buffer registers (Address: 02C016 , 02C216 , 02C416 , 02C616 ), the data will be transferred to DBBOUT0-3 automatically. The data of DBBOUT0-3 will be output to the data bus when there is a read request from host CPU and the status of bit2 (A2) of slave address (16 bits) is low.
LPCi address register H/L (LPC1ADH-LPC3ADH / LPC1ADL-LPC3ADL)
The slave address (16 bits) of LPC bus buffer channel 0 is fixed on 0060h, 0064h. The slave addresses (16 bits) of LPC bus buffer channel 1-3 are definable by setting LPC1-3 address registers H/L (02D016 to 02D516 ). The settings are for slave address upper 8 bits and lower 8 bits. And these registers can be set and cleared in any time. The bit 2 of LPC 1-3 address L is not decoded regardless of the setting value. When slave CPU reads LPC13 address registers, the bit2 (A2) of address low byte will be fixed to "0". The bit2 (A2) status of slave address is latched to XA2 flag when written by host CPU. The slave addresses that are already set in these registers will be used for comparing with the addresses to be received.
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 128 of 266
M16C/6KA Group
LPC Bus Interface
Data bus buffer control register 1
b7 b6 b5 b4 b3 b2 b1 b0
Symbol DBBCON1
Address 02C916
When reset 000000002
Bit symbol
OBF0SEL OBF00EN OBF01EN OBF1EN OBF2EN OBF3EN
Bit name
OBF0 output selection bit OBF00 output enable bit OBF01 output enable bit OBF1 output enable bit OBF2 output enable bit OBF3 output enable bit
Function
0 : OBF00 enable 1 : OBF01 enable 0 : P40 as GPIO 1 : P40 as OBF00 output 0 : P43 as GPIO 1 : P43 as OBF01 output 0 : P44 as GPIO 1 : P44 as OBF1 output 0 : P45 as GPIO 1 : P45 as OBF2 output 0 : P46 as GPIO 1 : P46 as OBF3 output
RW
Nothing is assigned. Cannot be written. The value is "0" in reading.
Fig.GF-3 Data bus buffer control registers
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 129 of 266
M16C/6KA Group
LPC Bus Interface
Data bus buffer status register
b7 b6 b5 b4 b3 b2 b1 b0
Symbol DBBSTS0 DBBSTS1 DBBSTS2 DBBSTS3
Address 02C116 02C316 02C516 02C716
When reset 000000002 000000002 000000002 000000002
Bit symbol
OBF IBF U2 XA2
Bit name
Output buffer full flag Input buffer full flag User definable flag XA2 flag
Function
0 : Buffer empty 1 : Buffer full 0 : Buffer empty 1 : Buffer full This flag can be freely defined by user This flag is indication the A2 status of the 16 bit slave address when IBF flag is set This flag can be freely defined by user
RW
U4 U5 U6 U7
User definable flag
Fig.GF-4 Data bus buffer status register
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 130 of 266
M16C/6KA Group
LPC Bus Interface
LPCi address register L (i=1,2,3)
b7 b6 b5 b4 b3 b2 b1 b0
(Note2) Address 02D016 02D216 02D416 When reset 000000002 000000002 000000002 RW
Symbol LPC1ADL LPC2ADL LPC3ADL
Bit symbol
LPCSAD0 LPCSAD1 LPCSAD2 LPCSAD3 LPCSAD4 LPCSAD5 LPCSAD6 LPCSAD7
Bit name
Slave address0 Slave address1 Slave address2 (Note1) Slave address3 Slave address4 Slave address5 Slave address6 Slave address7
Note1: Always returns "0" when read, even if writing "1" to this bit. Note2: Do not set the same 16 bits slave address in each channel.
LPCi address register H (i=1,2,3)
b7 b6 b5 b4 b3 b2 b1 b0
Symbol LPC1ADH LPC2ADH LPC3ADH
Address 02D116 02D316 02D516
When reset 000000002 000000002 000000002 RW
Bit symbol
LPCSAD8 LPCSAD9 LPCSAD10 LPCSAD11 LPCSAD12 LPCSAD13 LPCSAD14 LPCSAD15
Bit name
Slave address8 Slave address9 Slave address10 Slave address11 Slave address12 Slave address13 Slave address14 Slave address15
Fig.GF-5 LPC related registers
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z page 131 of 266
M16C/6KA Group
LPC Bus Interface
LPC control register (LPCCON)
* LPC bus interface enable bit (LPCBEN) "0": P30 -P36 use as GPIO "1": P30 -P36 use as LPC bus interface * LPC bus buffer 0 enable bit (LPCEN0) "0": LPC bus buffer0 disable "1": LPC bus buffer0 enable * LPC bus buffer 1 enable bit (LPCEN1) "0": LPC bus buffer1 disable "1": LPC bus buffer1 enable * LPC bus buffer 2 enable bit (LPCEN2) "0": LPC bus buffer2 disable "1": LPC bus buffer2 enable * LPC bus buffer 3 enable bit (LPCEN3) "0": LPC bus buffer3 disable "1": LPC bus buffer3 enable * LPC software reset bit (LPCSR)
______________
By setting the bit to "1", LPC interface is reset by the same status as LRESET="L". After 1.5 cycles of BCLK at writing "1", reset is released and the bit becomes "0". Nothing happens if "0" is set. * SYNC output selection bits (SYNCSEL0,SYNCSEL1) The content of SYNC output can be selected by bit 0,1 (SYNC output selection bits) of LPC control register. Fig.GF-6 shows the configuration of LPC control register, Table.GF-1 shows the content of SYNC output selected by SYNC output selection bits. Table GF-1 SYNC output SYNCSEL1 0 0 1 1 SYNCSEL0 0 1 0 1 SYNC cycle 1 4 1 4 1st cycle 00002 01102 10102 01102 SYNC output 2nd cycle 3rd cycle 01102 01102 01102 01102 4th cycle 00002 10102
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 132 of 266
M16C/6KA Group
LPC Bus Interface
LPC control register
b7 b6 b5 b4 b3 b2 b1 b0
Symbol LPCCON Bit symbol SYNCSEL0 SYNCSEL1 LPCSR LPCBEN LPCEN0 LPCEN1 LPCEN2 LPCEN3
Address 02D616 Bit name
b1 b0
When reset 000000002 Function 0 0: OK 0 1: Long & OK 1 0: Err 1 1: Long & Err 0 : The release of reset (Note) 1 : Reset 0 : P30 - P36 as GPIO 1 : LPC bus buffer enable 0 : LPC bus buffer 0 disable 1 : LPC bus buffer 0 enable 0 : LPC bus buffer 1 disable 1 : LPC bus buffer 1 enable 0 : LPC bus buffer 2 disable 1 : LPC bus buffer 2 enable 0 : LPC bus buffer 3 disable 1 : LPC bus buffer 3 enable RW
SYNC output selection bits
LPC software reset bit LPC interface enable bit LPC bus buffer 0 enable bit LPC bus buffer 1 enable bit LPC bus buffer 2 enable bit LPC bus buffer 3 enable bit
Note: For LPC software reset, the bit will automatically return to "0" after writing "1".
Fig.GF-6 LPC control register
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 133 of 266
M16C/6KA Group
LPC Bus Interface
Basic operation of LPC bus interface
The status transition of LPC bus interface is shown in Figure GF-7. Setting steps for using LPC bus interface is explained below. * Setting bit3 (LPC interface enable bit) of LPC control register ( address 02D616 ) to "1" * Choosing which LPC bus buffer channel will be used * Setting "1" to bits 4-7 (LPC bus buffer 0-3 enable bit) of LPC control register ( address 02D616 ). * The 16-bit slave address of LPC bus buffer channel is defined by writing 16-bit slave address to LPC 1-3 address registers ( address 02D016 to 02D516 ). If channel 1-3 LPC bus buffer is chosen, set the address to the corresponding address register. * Selecting IBF/ OBE interrupt in data bus buffer control register0 ( address 02C816 ) * Selecting OBF output port in data bus buffer control register1 ( address 02C916 ) <1> Example of I/O writing cycle from HOST Writing timing is shown in Figure GF-8. The basic communication cycles of LPC I/O protocol are 13 cycles. The data of LAD[3:0] will be read by the
_______________
rising edge of LCLK. Communication will start from LFRAME falling edge. ______________ * 1st cycle : When LFRAME is "Low", sending "00002 " to LAD[3:0] for communication start frame detecting. _______________ * 2nd cycle : When LFRAME is "High", sending "001X2 " to LAD[3:0] for write frame detecting. * From 3rd cycle to 6th cycle: These four cycles are detecting for 16 bits slave address. 3rd cycle: The slave address which is from host is written to slave address register [15:12] through LAD[3:0] 4th cycle: The slave address which is from host is written to slave address register [11:8] through LAD[3:0] 5th cycle: The slave address which is from host is written to slave address register [7:4] through LAD[3:0] 6th cycle: The slave address which is from host is written to slave address register [3:0] through LAD[3:0] * 7th and 8th cycles are used for one data byte transfer. 7th cycle: The data which is from host is written to input data buffer[3:0] through LAD[3:0] 8th cycle: The data which is from host is written to input data buffer[7:4] through LAD[3:0] * 9th and 10thcycles are for changing the communication direction from hostslave to slavehost 9th cycle: Host outputs "11112 " to LAD[3:0] 10thcycle: The LAD[3:0] will be set to Hi-Z by HOST to switch the communication direction. * 11th cycle: The "00002 " (SYNC OK) is output to LAD[3:0] for acknowledge. * 12th cycle: The "11112 " is output to LAD[3:0]. The XA2 and IBF flag are set. IBF interrupt signal is generated. * 13th cycle: The LAD[3:0] will be set to Hi-Z by slave to switch the communication direction. During the host write period, the bit2 (A2) status of 16 bits slave address will be latched to XA2 flag. When 8 bits data from input data buffer are read out by slave CPU, the IBF flag will be cleared simultaneously.
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 134 of 266
M16C/6KA Group
LPC Bus Interface
<2> Example for I/O reading cycle from HOST Reading timing is shown in Figure GF-9. The basic communication cycles of LPC I/O protocol are 13 cycles. The data of LAD[3:0] will be read by the _______________ rising edge of LCLK. Communication will start from LFRAME falling edge. _______________ * 1st cycle: When LFRAME is "Low", sending "00002 " to LAD[3:0] for communication start detecting. _______________ * 2ndcycle: When LFRAME is "High", the host send "000X2 " on LAD[3:0] to inform the cycle type as I/O read. * From 3rd cycle to 6thcycle: These four cycles are detecting for 16 bits slave address. 3rdcycle: The slave address which is from host is written to slave address register [15:12] throughLAD[3:0] 4thcycle: The slave address which is from host is written to slave address register [11:8] throughLAD[3:0] 5thcycle: The slave address which is from host is written to slave address register [7:4] throughLAD[3:0] 6thcycle: The slave address which is from host is written to slave address register [3:0] throughLAD[3:0] * 7th and 8thcycles are used for changing the communication direction from hostslave to slavehost 7thcycle: Host is output "11112 " to LAD[3:0] 8thcycle: The LAD[3:0] will be set to Hi-Z by HOST to switch the communication direction. * 9thcycle : The "00002 " (SYNC OK) is output to LAD[3:0] for acknowledge. * 10th and 11thcycles are for output 8 bits data from output data buffer or output 8 bits data from status register. 10thcycle: Sending output data buffer [3:0] to LAD[3:0] or sending data of status register [3:0] to LAD[3:0] 11thcycle: Sending output data buffer [7:4] to LAD[3:0] or sending data of status register [7:4] to LAD[3:0]. * 12thcycle: The "11112 " is output to LAD[3:0]. The OBF flag is cleared and OBE interrupt signal is generated. * 13thcycle: The LAD[3:0] will be set to Hi-Z by slave to switch the communication direction. OBF flag will be set when 8 bits data are written to output data buffer by slave CPU.
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 135 of 266
M16C/6KA Group
LPC Bus Interface
Data WR (I/O write cycle)
START WR 16 BIT ADDRESS DATA TAR SYNC TAR
LCLK
LFRAME (Note1) LAD [3:0]
Input buffer
XA2 flag
IBF flag Driven by the HOST Driven by the SLAVE
Command WR (I/O write cycle)
START WR 16 BIT ADDRESS DATA TAR SYNC TAR
LCLK
LFRAME (Note1) LAD [3:0]
Input buffer
XA2 flag
IBF flag Driven by the HOST Driven by the SLAVE
Note1 : LAD0 to LAD3 pins remain Hi-Z after transfer completion
Fig.GF-7 Data and Command write timing figure
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 136 of 266
M16C/6KA Group
LPC Bus Interface
Data RD (I/O read cycle)
START RD 16 BIT ADDRESS TAR SYNC DATA TAR
LCLK
LFRAME (Note1) LAD [3:0]
OBF flag Driven by the HOST Driven by the SLAVE
Status RD (I/O read cycle)
START RD 16 BIT ADDRESS TAR SYNC DATA TAR
LCLK
LFRAME (Note1) LAD [3:0]
OBF flag
(Note2)
Driven by the HOST
Driven by the SLAVE
Note1 : LAD0 to LAD3 pins become Hi-Z after transfer completion. Note2 : OBF flag does not change.
Fig.GF-8 Data and Status read timing figure
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 137 of 266
Table GF-2 Function explanation of the control input and output pins in LPC bus interface function
HOSTEN
M16C/6KA Group
Pin name Function
02C916 Bit 1 02C916 Bit 2 02C916 Bit 3 02C916 Bit 4 02C916 Bit 5 02C916 Bit 6
Name
LPC interface enable bit OBF00 OBF01 output output enable bit enable bit OBF3 output enable bit control bit OBF1 OBF2 output output enable bit enable bit
OBF0 output enable bit
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
Input/ Output
02D616 Bit 3
02C916 Bit 0
P30/LAD0
LAD0
1
I/O I/O I/O I/O I I I
1 0
It is used for indicating the start of LPC cycle and termination of abnormal communication cycle. LPC reset signal. LPC bus interface function is reset. LPC synchronous clock signal. Status output signal. OBF00 output. Status output signal. OBF01 output. Status output signal. OBF1 output.
P31/LAD1
LAD1
1
LPC bus used for transmitting and receiving address, command and data between Host CPU and peripheral devices.
P32/LAD2
LAD2
1
page 138 of 266
P33/LAD3
LAD3
1
LPC Bus Interface
P34/LFRAME LFRAME
1
P35/LRESET
LRESET
1
P36/LCLK
LCLK
1
P40/OBF00
OBF00
0
O O
1 1 1
P43/OBF01
OBF01
1 0 1
P44/OBF1
OBF1
O O O
P45/OBF2
OBF2
Status output signal. OBF2 output. Status output signal. OBF3 output.
P46/OBF3
OBF3
M16C/6KA Group
LPC Bus Interface
______________
Table GF-3 Conditions of LPC bus interface function induced by LRESET input
______________ ______________
Pin name / Internal register P30/LAD0 P31/LAD1 P32/LAD2 P33/LAD3
_________________
LRESET="H" LPC bus interface function(function is select) I/O port
LRESET="L"
Note
Pin
P34/LFRAME _______________ P35/LRESET P36/LCLK P40/OBF00 P43/OBF01 P44/OBF1 P45/OBF2 P46/OBF3 P42/GateA20 Input data bus buffer Output data bus buffer U flag 7,6,5,4,2 XA2 flag
I/O port LPC bus interface function I/O port OBF output is enable until LRESET="L". A spike pulse may be output to the port when the port is already set to L output port and OBF signal is output to the port ______________ just before LRESET is set to L.
______________
unstable It can't be written by slave side. It can be written and read by Initialization to "0" only for slave side. Initialization to "0" Initialization to "0" Initialization to "0" It can be written and read by slave side. It can be written and read by slave side. Initialization DBBSTS0. There is possibility to generate IBF interrupt request. There is possibility to generate OBE interrupt request.
Internal register
IBF flag OBF flag LPCADH/L LPCCON GA20 circuit
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 139 of 266
M16C/6KA Group
LPC Bus Interface
GateA20 output function
The GateA20 pin (port P42) can be controlled by LPC interface function channel 0 in hardware. Hardware GateA20 is sharing with P42 pin. Setting "1" to bit 0 of GateA20 control register enables the hardware GateA20 function. The default value of hardware GateA20 is "1". The GateA20 control register is shown in Fig.GF-9. When the host CPU writes "D1" command to address 006416, and then writes data to address 006016 in succession, the value of bit 1 of the data will be output to GateA20 pin. The timing is shown in Fig.GF-10. The GateA20 operation sequences are shown in Fig.GF-11, Fig.GF-12. As shown in the figures, there is no change in input buffer full flag(IBF0) and no input buffer full(IBF) interrupt request, but the input data bus buffer and XA2 flag are changed in these sequences. The value of the GateA20 output pin will be held till the data next to D1 command is written in. P42 becomes _____________ I/O port and the the value of GateA20 becomes "0" when LRESET input is "L". GateA20 will be initialized even if the sequence is executed. However, the GateA20 enable bit will not be changed and GateA20 output pin _____________ will be resumed after the LRESET input becomes "H".
GateA20 control register
b7 b6 b5 b4 b3 b2 b1 b0
0
Symbol GA20CON
Address 002CA16
Reset 0016
Bit Symbol
GA20EN
Bit name
GateA20 enable bit
Function
0 : P42 as GPIO 1 : Hardware GateA20 function enable Must be set to "0"
RW
Reserved bit
Nothing is assigned. Meaningless in writing. "0" in reading.
Fig.GF-9 GateA20 control register
START
WRITE
16-bit address
DATA
TAR
SYNC
TAR
LCLK
LFRAME
LAD (3:0)
GateA20 pin
Previous value
The value of bit 1 of the data
Fig.GF-10 GateA20 output timing
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z page 140 of 266
M16C/6KA Group
LPC Bus Interface
Sequence 1 (basic operation 1)
LPC communication GateA20 pin IBF0 flag refresh IBF interrupt request
Write D1 to 006416 Write data to 006016 Write FF to 006416
Previous value No No No No
Bit 1 value of the data No No
Sequence 2 (basic operation 2)
LPC communication GateA20 pin IBF0 flag refresh IBF interrupt request
Write D1 to 006416 Write data to 006016
Write data other than FF and D1 to 006416
Previous value No No No No
Bit 1 value of the data Yes Yes
Sequence 3 (basic operation 3)
LPC communication GateA20 pin IBF0 flag refresh IBF interrupt request
Write D1 to 006416 Write data to 006016 Write data to 006016
Previous value No No No No
Bit 1 value of the data Yes Yes
Fig.GF-11 GateA20 operation sequence (1)
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 141 of 266
M16C/6KA Group
LPC Bus Interface
Sequence 4 (re-trigger)
LPC communication GateA20 pin IBF0 flag refresh IBF interrupt request
Write D1 to 006416 Write D1 to 006416 Write data to 006016
Previous value No No No No No
Bit 1 value of the data
No
Sequence 5 (cancel operation)
LPC communication
Write D1 to 006416
Write data other than D1 to 006416
GateA20 pin IBF0 flag refresh IBF interrupt request
Previous value No No Yes Yes
Sequence 6 (continuance operation)
LPC communication
Write D1 to 006416 Write data1 to 006016 Write D1 to 006416 Write data2 to 006016
GateA20 pin IBF0 flag refresh IBF interrupt request
Previous value No No No No
Bit 1 value of the data No No No No
The value of bit 1 of data 2
Fig.GF-12 GateA20 operation sequence (2)
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 142 of 266
M16C/6KA Group
Serial Interrupt Output
Serial Interrupt Output
The serial interrupt output is the circuit that outputs the interrupt request to the host with serial interrupt data format. Tab.SI-1 shows the specification of serial interrupt output. Table.SI-1 Specifications of serial interrupt output
Item The factors of serial interrupt Specification The numbers of serial interrupt requests (numbers of channels) that can output simultaneously are 5 factors. Each interrupt factor of each channel is explained as follows. * Channel 0 (1) By setting "1" to IRQi request bit (bit 5, 6 i=1,12) of IRQ request register 0, the interrupt request can be generated. (2) Synchronized with OBF00 and OBF01 that are the host bus interface internal signals, the serial interrupt request can be generated. * Channel 1-3 (1) By setting "1" to IRQ request bit (bit 5) of IRQ request register 1-3, the interrupt request can be generated. (2) Synchronized with OBF1-3 that are the host bus interface internal signals, the serial interrupt request can be generated. * Channel 4 By setting "1" to IRQ request bit (bit 5) of IRQ request register 4, the interrupt request can be generated. * Channel 0 (1) Setting the IRQ1 request bit (bit 5) of IRQ request register0 to "1" or detecting OBF00, which is the host bus interface internal signal, selects Frame 1. (2) Setting the IRQ12 request bit (bit 6) of IRQ request register0 to "1" or detecting OBF01, which is the host bus interface internal signal, selects Frame 12. * Channel 1-4 Selecting the frame select bit (bit 0-4) of IRQ request register1-4 selects Frame 1-15 or extend Frame 0-10. The operation synchronized with LCLK (Max. 33MHz). (Note) Setting the clock restart enable bit (bit 6) of serial interrupt control register0 to "1" requests the clock restart if the clock has stopped or slowed down in serial interrupt output. Setting the clock stop inhibition bit (bit 5) of serial interrupt control register0 to "1" requests the inhibition of clock stop if the clock tends to stop or slow down in serial interrupt output. Setting the OBF00, OBF01, OBF1-3 sync enable bit (bit 0-4) of serial interrupt control register0 to "1" enables the OBF synchronization.
The number of frame
Operation clock Clock restart
Clock stop inhibition
OBF sync enable
Note: To enable LCLK, it is necessary to enable the LPC bus interface function.
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 143 of 266
M16C/6KA Group
Serial Interrupt Output
internal data bus Serial interrupt control register0 (address:02B016 ) IRQ request register0 (address:02B216 ) IRQ request register1 - 4 (address:02B316 , 02B416, 02B516 ,02B616) b7 b6 b5 b4 b3 b2 b1 b0
b7 b6 b5 b4 b3 b2 b1 b0
b7 b6 b5 b4 b3 b2 b1 b0
Clock stop inhibiting enable Clock restart enable
IRQ request 00,01
IRQ request 1 - 4
OBF sync enable Serial interrupt enable Internal signals OBF00,OBF01, OBF1 - OBF3 Serial interrupt request Control circuit IRQ request 0 - 4 IRQ frame number 1 - 4
Port control section
IRQ request 0-4
IRQ request clear
Frame number (CH0 - CH4)
SERIRQ
Serial interrupt output Control circuit
Clock operation Status & finish acknowledge
Clock restart request & start frame start request
Clock monitor/ Control circuit
CLKRUN LCLK Reset selection LRESET b7 b6 b5 b4 b3 b2 b1 b0 PRST Serial interrupt control register1(address: 02B116 ) f1 Internal data bus
Fig.SI-1 Serial interrupt block chart
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 144 of 266
M16C/6KA Group
Serial Interrupt Output
(1) Register explanation
Fig.SI-2 shows the configuration of IRQ request register0, Fig.SI-3 shows the configuration of IRQ request register1-4, Fig.SI-4, SI-5 show the configurations of serial interrupt control register0,1 respectively.
q IRQ request register0 IRQR0
The serial interrupt request of Channel 0 is set by software.
*IRQ1 request bit IR0
Setting the bit to "1" generates the serial interrupt request (Frame 1). By setting the OBF00 sync enable bit (bit 0) of the serial interrupt control register0 to "1", the value of IR0 is the same as that of OBF00, which is the host bus interface internal signal. When the internal signal OBF00 is "1", the serial interrupt is generated. IR0 is cleared to "0" by writing "0" in software. IR0 can not be cleared to "0" by software when the internal signal OBF00 is "1" if OBF00 sync enable bit is set to "1".
*IRQ12 request bit IR1
Setting the bit to "1" generates the serial interrupt request (Frame 12). By setting the OBF01 sync enable bit (bit 1) of the serial interrupt control register0 to "1", the value of IR1 is the same with that of OBF01, which is the host bus interface internal signal. When the internal signal OBF01 is "1", the serial interrupt is generated. IR1 is cleared to "0" by writing "0" in software. IR1 can not be cleared to "0" by software when the internal signal OBF01 is "1" if OBF01 sync enable bit is set to "1".
IRQ request register0
b7 b6 b5 b4 b3 b2 b1 b0
Symbol: IRQR0 Bit symbol
Address: 02B216
When reset: 0016 Function
RW
Bit name Nothing is assigned. Meaningless in writing, "0" in reading. IR0 IR1 IRQ1 request bit IRQ12 request bit
0: No IRQ1 request 1: IRQ1 request 0: No IRQ12 request 1: IRQ12 request
Nothing is assigned. Meaningless in writing, "0" in reading.
Fig.SI-2 Configuration of IRQ request register0
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z page 145 of 266
M16C/6KA Group
Serial Interrupt Output
q IRQ request register i IRQRi (i=1-4)
The serial interrupt request of Channel 1-4 is set by software, or asserting frame is selected.
*IRQ request bit IR
Setting the bit to "1" generates the serial interrupt request. By setting the OBFj sync enable bit (bit2-4, j=1-3) of the serial interrupt control register0 to "1", the value of IR is the same as that of OBFj, which is the host bus interface internal signal. When the internal signal OBFj is "1", the serial interrupt is generated. IR is cleared to "0" by writing "0" in software. IR can not be cleared to "0" by software when the internal signal OBFj is "1" if OBFj sync enable bit is set to "1".
q IRQ select bit IS0-4
The asserting frame is selected.
IRQ request register1-4
b7 b6 b5 b4 b3 b2 b1 b0
Symbol IRQR1 IRQR2 IRQR3 IRQR4
Bit symbol IS0
Address 02B316 02B416 02B516 02B616
Bit name
When reset 0016 0016 0016 0016
Function IRQ Frame 0 0 0 0 0 : No SERIRQ output 0 0 0 0 1 : Frame 1 0 0 0 1 0 : Frame 2 0 0 0 1 1 : Frame 3 0 0 1 0 0 : Frame 4 0 0 1 0 1 : Frame 5 0 0 1 1 0 : Frame 6 0 0 1 1 1 : Frame 7 0 1 0 0 0 : Frame 8 0 1 0 0 1 : Frame 9 0 1 0 1 0 : Frame 10 0 1 0 1 1 : Frame 11 0 1 1 0 0 : Frame 12 0 1 1 0 1 : Frame 13 0 1 1 1 0 : Frame 14 0 1 1 1 1 : Frame 15 1 0 0 0 0 : Can't select 1 0 0 0 1 : Can't select 1 0 0 1 0 : Can't select 1 0 0 1 1 : Can't select 1 0 1 0 0 : Can't select 1 0 1 0 1 : Extend Frame 0 1 0 1 1 0 : Extend Frame 1 1 0 1 1 1 : Extend Frame 2 1 1 0 0 0 : Extend Frame 3 1 1 0 0 1 : Extend Frame 4 1 1 0 1 0 : Extend Frame 5 1 1 0 1 1 : Extend Frame 6 1 1 1 0 0 : Extend Frame 7 1 1 1 0 1 : Extend Frame 8 1 1 1 1 0 : Extend Frame 9 1 1 1 1 1 : Extend Frame 10
b4b3b2b1b0
RW
Frame select bit
IS1
IS2
IS3
IS4
IR
IRQ request bit
0: No IRQ request 1: IRQ request
Nothing is assigned. Meaningless in writing, "0" in reading.
Fig.SI-3 Configuration of IRQ request register1-4
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z page 146 of 266
M16C/6KA Group
Serial Interrupt Output
q Serial interrupt control register0 SERCON0
The operation condition of serial interrupt is set.
*OBFi sync enable bit SENi (i=00,01,1-3)
By setting the bit to "1", sync with the OBFi of host interface, the serialized interrupt can be generated.
*Clock stop inhibition bit SUPEN
Setting the bit to "1" will request the inhibition of clock if the clock tends to stop or slow down in serial interrupt request.
*Clock restart enable bit RUNEN
Setting the bit to "1" requests the clock restart during the clock stop or clock slow down in serial interrupt request.
*Serial interrupt enable bit IRQEN
__________ _______________
0: SERIRQ, PRST, CLKRUN are I/O ports. __________ _______________ 1: SERIRQ, PRST, CLKRUN are serial interrupt function ports.
Serial interrupt control register0
b7 b6 b5 b4 b3 b2 b1 b0
Symbol SERCON0 Bit symbol SEN00 SEN01 SEN1 SEN2 SEN3 SUPEN
(Note 1)
Address 02B016 Bit name
When reset 0016 Function 0: Sync inhibition 1: Sync enable 0: Sync inhibition 1: Sync enable 0: Sync inhibition 1: Sync enable 0: Sync inhibition 1: Sync enable 0: Sync inhibition 1: Sync enable 0: Stop control operation 1: No stop control operation 0: No clock restart 1: Clock restart 0: Serial interrupt inhibition 1: Serial interrupt enable
_______________
RW
OBF00 sync enable bit OBF01 sync enable bit OBF1 sync enable bit OBF2 sync enable bit OBF3 sync enable bit Clock stop inhibition bit Clock restart enable bit Serial interrupt enable bit
RUNEN
(Note 1)
IRQEN
(Note 2)
Note 1 : When IRQEN is set to "1", if either SUPEN or RUNEN is set to "1", P46 will function as CLKRUN I/O and the output type is N channel open drain. __________ __________ Note 2 : When the bit is set to "1", P43, P45 function as SERIRQ, PRST respectively. Even the bit is set to "1", P45/PRST can function as GPIO if bit 1 of serial interrupt control register 1 (address 02B116) is set to "1".
Fig.SI-4 Configuration of serial interrupt control register0
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 147 of 266
M16C/6KA Group
Serial Interrupt Output
q Serial interrupt control register1 SERCON1
The register is for setting the pins of serial interrupt.
*Reset selection bit RSEL
__________
0: The input of PRST is the reset signal. ______________ 1: The input of LRESET is the reset signal. (Note1) __________ Note 1: The PRST pin becomes I/O port if setting the bit to "1".
Serial interrupt control register 1
b7 b6 b5 b4 b3 b2 b1 b0
0
00
0
0
Symbol SERCON1 Bit symbol Reserved bit RSEL Reserved bit
Address 02B116 Bit name
When reset 0016 Function Must be "0". RW
Reset selection bit
0 : Select PRST pin. 1 : Select LRESET pin. Must be "0". 0 : OBF00 and OBF01 are independent. 1 : OBF00 and OBF01 are merged (logical OR). 0: Normal operation 1: SEN00, SEN01 is cleared when OBF0 is cleared. Must be "0".
OBF0MRG
OBF0 mergence bit
OBF0CLR
OBF0 cut sync bit
Reserved bit
Fig.SI-5 Configuration of serial interrupt control register1
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 148 of 266
M16C/6KA Group
Serial Interrupt Output
*OBF0 mergence function
By setting the bit to "1", the signal, which is logically OR by OBF00 and OBF01 signals from LPC bus interface, will output to IRQ1 and IRQ12 of serial interrupt circuit. With the function, the IRQ1 and IRQ12 request bits can be cleared simultaneously by H/W at the read of output data buffer from system if both IRQ1 and IRQ12 request bits are set in the case that IRQ1 request bit (or IRQ12 request bit) is set after that of IRQ12 (or IRQ1) because of the overwrite to the output data buffer.
*OBF0 sync inhibitant function
By setting bit 4 of serial interrupt control register 1 (OBF cut sync bit), simultaneously after the read of OBF0, the OBF0 sync function can be inhibited. If the bit is set to "1", simultaneously after the clear of OBF00 or OBF01, SEN00 (OBF00 sync enable bit) and SEN01 (OBF01 sync enable bit) bits are cleared (sync inhibitation) by H/W. The configuration of serial interrupt control register 1 and the switching circuit controlled by OBF0MRG, OBF0CLR are shown in Fig. SI-5, Fig. SI-6 respectively.
OBF0CLR OBF0MRG OBF0 OBF0
"0"
RD RD/WR
OBF0001
SEN00 To IRQ1 request bit of serial interrupt circuit WR IR0
"1"
OBF0 clear signal (Triggered by host read)
"0"
RD/WR
OBF0001
SEN01 To IRQ12 request bit of serial interrupt circuit WR IR0 RD
OBF0SEL
"1"
Fig.SI-6 The switching circuit controlled by OBF0MRG, OBF0CLR
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 149 of 266
M16C/6KA Group
Serial Interrupt Output
q Serial interrupt control register2 SERCON2
The polarity of serial interrupt output can be selected by bit 0 to bit 5 of serial interrupt control register 2.
When the bit is set to "0": If there is a request, Hiz-Hiz-Hiz If there is no request, L-H-Hiz When the bit is set to "1": If there is a request, L-H-Hiz If there is no request, Hiz-Hiz-Hiz Only the default value of bit 4 (serial interrupt polarity bit 3) of serial interrupt control register 2 after reset is "1". Fig.SI-7 shows the configuration of serial interrupt control register 2.
Serial interrupt control register 2
b7 b6 b5 b4 b3 b2 b1 b0
Symbol SERCON2 Bit symbol SERSEL00
Address 02B716 Bit name
When reset 1016 Function Select serial interrupt output polarity of IRQ1 in channel 0. (Note) Select serial interrupt output polarity of IRQ12 in channel 0. (Note) Select serial interrupt output polarity of IRQ in channel 1. (Note) Select serial interrupt output polarity of IRQ in channel 2. (Note) Select serial interrupt output polarity of IRQ in channel 3. (Note) Select serial interrupt output polarity of IRQ in channel 4. (Note) RW
Serial interrupt polarity selection bit 00 Serial interrupt polarity selection bit 01 Serial interrupt polarity selection bit 1 Serial interrupt polarity selection bit 2 Serial interrupt polarity selection bit 3 Serial interrupt polarity selection bit 4
SERSEL01
SERSEL1
SERSEL2
SERSEL3
SERSEL4
Nothing is assigned. Meaningless in writing. "0" in reading. Note: "0" "1" : If there is a request If there is no request : If there is a request If there is no request Hiz-Hiz-Hiz L-H-Hiz L-H-Hiz Hiz-Hiz-Hiz
Fig.SI-7 The configuration of serial interrupt control register 2
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 150 of 266
M16C/6KA Group
Serial Interrupt Output
(2) The operation of serial interrupt
A cycle operation of serial interrupt starts with start frame and finishes with stop frame. There are 2 kinds of operation mode: continuous mode and quiet mode. The next operation mode is judged by monitoring the length of stop frame sent from host side.
q The timing of serial interrupt cycle
Fig.SI-8 shows an example of basic timing of serial interrupt cycle. Start frame The start frame will be detected if the SERIRQ remains "L" in 4-8 clock cycles. IRQ data frame Each IRQ data frame is 3 clock cycles. *Channel 0-2,4:If the IRQ request bit is "0", then the SERIRQ is driven to "L" during the 1st clock cycle of the corresponding data frame, to "H" during the 2nd clock cycle, to high impedance during the 3rd clock cycle. If the IRQ request bit is "1", then the SERIRQ is high impedance during all of the 3 clock cycles. *Channel 3:If the IRQ request bit is "0", then the SERIRQ is high impedance during all of the 3 clock cycles. If the IRQ request bit is "1", then the SERIRQ is driven to "L" during the 1st clock cycle of the corresponding data frame, to "H" during the 2nd clock cycle, to high impedance during the 3rd clock cycle. Serial Interrupt output polarity of each channel can changed by Serial Interrupt polarity selection bit i (i=00, 01, 1, 2, 3, 4) of Serial Interrupt control register 2. zStop frame The stop frame will be detected if the SERIRQ remains "L" in 2 or 3 clock cycles. The next operation mode is quiet mode if the length of "L" is 2 clock cycles, the continuous mode if the length is 3 clock cycles.
Start frame Clock SERIRQ Driver source System side
frame 0
frame 1
frame 15
IOCHK
Stop frame
to the next cycle
Device side
Device side
System side
Fig.SI-8 Basic timing of serial interrupt cycle
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 151 of 266
M16C/6KA Group
Serial Interrupt Output
q Operation mode
Fig.SI-9 shows an example of timing of continuous mode, Fig.SI-10 shows that of quiet mode. Continuous mode __________ _______________ After reset, at the rising edge of PRST (or LRESET) or the length of the last stop frame of serial interrupt cycle being 3 clock cycles, it will be the continuous mode. After receiving the start frame (Note 1), the Frame 1, Frame 12 or frames selected in each channel will be asserted. Note 1: If the length of "L" is less than 4 clock cycles or more than 9 clock cycles, the start frame will not be detected and the next start (the falling edge of SERIRQ) is waited.
Start frame (Note1) Clock SERIRQ line System*SERIRQ output Device*SERIRQ output Driver source System side Device side IRQ0 frame IRQ1 frame IRQ2 frame IRQ3 frame
Note1 . The start frame is set to 4 clock as setting exemple
Fig.SI-9 Timing diagram of continuous mode
Quiet mode At clock stop or clock slow down, or the length of the last stop frame of serial interrupt cycle being 2 clock cycles, it will be the quiet mode. In this mode the SERIRQ is driven to "L" in the 1st clock cycle by device and after the receiving of the rest start frame (Note 1) from host, the IRQ1 Frame , IRQ12 Frame or frames selected in each channel will be asserted. Note 1: If the sum of length of "L" that is driven by the device in the 1st clock cycle and by the host in the rest clock cycles is within 4-8 clock cycles, the start frame will be detected. If the sum of length of "L" is less than 4 clock cycles or more than 9 clock cycles, the start frame will not be detected and the next start (the falling edge of SERIRQ) is waited.
Start frame (Note1)
IRQ0 frame
IRQ1 frame
IRQ2 frame
IRQ3 frame
LCLK SERIRQ line System*SERIRQ output Device*SERIRQ output Driver source Device side System side Device side
Note1 . The start frame is set to 4 clock as setting example
Fig.SI-10 Timing diagram of quiet mode
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 152 of 266
M16C/6KA Group
Serial Interrupt Output
(3) Clock restart/ stop inhibition request
_______________
Asserting the CLKRUN signal can request to restart or maintain the clock which stops or slows down or request the host to tend to stop or slow down. Fig.SI-11 shows an example of timing of clock restart request, Fig.SI-12 shows an example of timing of clock stop inhibition request. Clock restart operation Setting the clock restart bit of serial interrupt control register0 to "1" will request the clock restart if the clock has slowed down or stopped at serial interrupt request.
LCLK CLKRUN line System*CLKRUN Device*CLKRUN SERIRQ line System*SERIRQ Device*SERIRQ Restart frame Start frame
f1 Serial interrupt request Internal Interrupt restart request signal
Fig.SI-11 Timing diagram of clock restart request
Clock stop inhibition request Setting the clock stop inhibition bit of serial interrupt control register0 to "1" will request the inhibition of clock stop if the clock tends to stop or slow down during all the period of serial interrupt output.
Clock CLKRUN line System*CLKRUN Device*CLKRUN SERIRQ line Serial interrupt request Inhibition request A cycle of serial interrupt
Internal Interrupt Inhibition request signal
Fig.SI-12 Example of timing of clock stop inhibition request
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 153 of 266
M16C/6KA Group
MULTI-MASTER I2C-BUS Interface
MULTI-MASTER I2C-BUS INTERFACE
The multi-master I2C-BUS interface is a serial communication circuit based on Philips I2C-BUS data transfer format. 3 independent channels, with both arbitration lost detection and a synchronous functions, are built in for the multi-master serial communication. Fig.GC-1 shows a block diagram of the multi-master I2C-BUS interface and Table.GC-1 lists the multi-master I2C-BUS interface functions. The multi-master I2C-BUS interface consists of the I2C address register, the I2C data shift register, the I2C clock control register, the I2C control register 1, I2C control register 2, the I2C status register, the I2C start/stop condition control register and other control circuits. Table.GC-1 Multi-master I2C-BUS interface functions Item Function Based on Philips I2C-BUS standard: 10-bit addressing format 7-bit addressing format High-speed clock mode Standard clock mode Based on Philips I2C-BUS standard: Master transmission Master reception Slave transmission Slave reception 16.1kHz to 400kHz (at VIIC = 4MHz)
Format
Communication mode
SCL clock frequency
*VIIC=I2C system clock
: Purchase of Renesas Technology Corporation's I2C components conveys a license under the Philips I2C Patent Rights to use these components an I2C system, provided that the system conforms to the I2C Standard Specification as defined by Philips.
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 154 of 266
M16C/6KA Group
I2C Control register 1
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
b7
SAD6 SAD5 SAD4 SAD3 SAD2 SAD1 SAD0 RBW
b7
b0
S3D
ICK1
ICK0 SCLM SDAM
WIT
SIM
I2C address register b0
Interrupt generating circuit
Interrupt generating circuit
Interrupt request signal (SCLSDAIRQ)
S0D
Address comparator
Fig.GC-1 Block diagram of multi-master I2C-BUS interface
Interrupt request signal (I2CIRQ) Data control circuit
page 155 of 266
b7
I2C data shift register S0
Serial data
(SDA) b7
Noise elimination circuit b0
b0
AL AAS AD0 LRB
S2D AL
circuit
MST TRX BB PIN I 2 C status register
STSP SIS SIP SSC4 SSC3 SSC2 SSC1 SSC0 SEL
I C start/stop condition control register Internal data bud
2 I C control register 2
MULTI-MASTER I2C-BUS Interface
2
S1
BB
circuit S4D
TOSEL TOF TOE
2
Serial
Timeout detection circuit
clock (SCL) b7 b0
FAST ACK MODE CCR4 CCR3 CCR2 CCR1 CCR0 BIT
b7
TISS
Noise elimination circuit
ACK
2 S2 I C clock control register
Clock control circuit
I C control register 0 S1D
10BIT ALS SAD
b0
ES0 BC2 BC1 BC0 System clock select circuit ICK1,ICK0=1,0 1/2 ICK1,ICK0=0,1 ICK1,ICK0=0,0 ICK1,ICK0=1,1 1/2 1/2 1/2 f1 Bit count
Clock division I2C system clock (VIIC)
ICCK(External clock)
M16C/6KA Group
MULTI-MASTER I2C-BUS Interface
I2C Data Shift Register
The I2C data shift register (address 032016, 033016, 031016) is an 8-bit shift register to store receiving data and write transmission data. When transmit data is written into this register, it is transferred to the outside from bit 7 in synchronization with the SCL clock, and each time one-bit data is output, the data of this register are shifted by one bit to the left. When data is received, it is input to this register from bit 0 in synchronization with the SCL clock, and each time one-bit data is input, the data of this register are shifted by one bit to the left. The timing of storing received data to this register is shown in figure GC-3.The I2C data shift register is in a write enable status only when the I2C-BUS interface enable bit (ES0 bit : bit 3 of address 032316, 033316, 031316) of the I2C control register 0 is "1". The bit counter is reset by a write instruction to the I2C data shift register. When both the ES0 bit and the MST bit of the I2C status register (address 032816, 033816, 031816) are "1", the SCL is output by a write instruction to the I2C data shift register. Reading data from the I2C data shift register is always enabled regardless of the value of ES0 bit.
I C data shift register
b7 b6 b5 b4 b3 b2 b1 b0
2
Symbol S0i(i=0,1,2)
Address 032016,033016,031016
When reset --
Function Transmission data /receiving data are stored. In the master transmission mode, the start condition/ stop condition are triggered by writing data to the register (refer to the section on the method to generate the start/stop condition). The transmission/receiving are started synchronized with SCL.
RW
Note
Note The write is only enabled when bus interface enable bit (ES0 bit) is "1". Because the register is used both for storing transmission data/receiving data, the transmission data should be written after the receiving data are read out before writing transmission data to this register.
Fig.GC-2 I2C data shift register
SCL SDA
tdfil
Internal SCL Internal SDA
tdfil : Noise elimination circuit delay time
1 to 2 VIIC cycle
tdfil
Shift clock
tdsft
Storing data at shift clock rising edge.
tdsf : Shift clock delay time 1 VIIC cycle
Fig.GC-3 The timing of receiving data stored to I2C data shift register
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 156 of 266
M16C/6KA Group
MULTI-MASTER I2C-BUS Interface
I2C Address Register
The I2C address register (address 032216, 033216, 031216) consists of a 7-bit slave address and a read/ write bit. In the addressing mode, the slave address written in this register is compared with the address data to be received immediately after the START condition is detected. *Bit 0: Read/write bit (RBW) This is not used in the 7-bit addressing mode. In the 10-bit addressing mode, the first byte address data to be received are compared with the contents (SAD6 to SAD0 + RBW) of the I2C address register. The RBW bit is cleared to "0" automatically when the stop condition is detected. *Bits 1 to 7: Slave address (SAD0-SAD6) These bits store slave addresses. Regardless of the 7-bit addressing mode or the 10-bit addressing mode, the address data transmitted from the master is compared with the contents of these bits.
I C address register
b7 b6 b5 b4 b3 b2 b1 b0
2
Symbol S0Di(i=0,1,2)
Address 032216,033216,031216
When reset 000000002
Bit Symbol
RBW
Bit name
Read/Write bit
Function
This bit is using for comparing with receiving address data in the 10-bit address mode. (Note) For comparing with received address data
R
W
SAD0 SAD1 SAD2 SAD3 SAD4 SAD5 SAD6
Slave address
Note.The RBW bit is cleared to "0" automatically when stop condition is detected
Fig.GC-4 I2C address register
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 157 of 266
M16C/6KA Group
MULTI-MASTER I2C-BUS Interface
I2C Clock Control Register
The I2C clock control register 0,1 (address 032416, 033416, 031416) is used to set ACK control, SCL mode and SCL frequency. *Bits 0 to 4: SCL frequency control bits (CCR0-CCR4) These bits control the SCL frequency. Refer to Table GC-2. *Bit 5: SCL mode specification bit (FAST MODE) This bit specifies the SCL mode. When this bit is set to "0", the standard clock mode is selected. When the bit is set to "1" , the high-speed clock mode is selected. When connecting to the bus with the high-speed mode I2C-BUS standard (maximum 400 kbits/s), set 4 MHz or more to I2C system clock(VIIC). *Bit 6: ACK bit (ACK BIT) This bit sets the SDA status when an ACK clock is generated. When this bit is set to "0", the ACK return mode is selected and SDA goes to "L" at the occurrence of an ACK clock. When the bit is set to "1", the ACK nonreturn mode is selected. The SDA is held in the "H" status at the occurrence of an ACK clock. However, when the slave address agrees with the address data in the reception of address data at ACK BIT = "0", the SDA is automatically made "L" (ACK is returned). If there is a disagreement between the slave address and the address data, the SDA is automatically made "H" (ACK is not returned). *ACK clock: Clock for acknowledgment *Bit 7: ACK clock bit (ACK) This bit specifies the mode of acknowledgment which responses to the data transferring. When this bit is set to "0", the no ACK clock mode is selected. In this case, no ACK clock occurs after data transmission. When the bit is set to "1", the ACK clock mode is selected and the master generates an ACK clock at the completion of each 1-byte data transfer. The device for transmitting address data and control data releases the SDA at the occurrence of an ACK clock (makes SDA "H") and receives the ACK bit generated by the data receiving device. Note: Except for ACK bit (ACKBIT), do not write data into the I2C clock control register during transfer. If data is written during transfer, the I2C clock generator is reset, so that data cannot be transferred normally.
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 158 of 266
M16C/6KA Group
MULTI-MASTER I2C-BUS Interface
I C clock control register
b7 b6 b5 b4 b3 b2 b1 b0
2
Symbol S2i(i=0,1,2)
Address 032416,033416,031416
When reset 000000002
Bit Symbol
CCR0 CCR1 CCR2 CCR3 CCR4 FAST MODE ACK BIT ACK
Bit name
SCL frequency control bits
Function
Refer to table.GC-2
RW
SCL mode specification bit ACK bit ACK clock bit
0 : Standard clock mode 1 : High-speed clock mode 0 : ACK is returned 1 : ACK is not returned 0 : No ACK clock 1 : ACK clock
Fig.GC-5 I2C clock register
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 159 of 266
M16C/6KA Group
MULTI-MASTER I2C-BUS Interface
Table.GC-2 Set values of I2C clock control register and SCL frequency Setting value of CCR4 to CCR0 CCR4 CCR3 CCR2 CCR1 CCR0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 1 1 0 0 1 0 0 0 0 1 0 1 0 0 1 1 0 SCL frequency (at VIIC=4MHz, unit : kHz) (Note1) Standard clock mode High-speed clock mode Setting disabled Setting disabled Setting disabled Setting disabled Setting disabled Setting disabled - (Note2) 333 - (Note2) 250 100 400 (Note3) 83.3 166 500 / CCR value 1000 / CCR value (Note3) (Note3) 17.2 34.5 16.6 33.3 16.1 32.3
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
1 1 1
Notes 1:Duty of SCL clock output is 50 %. The duty becomes 35 to 45 % only when the high-speed clock mode is selected and CCR value = 5 (400 kHz, at VIIC = 4 MHz). "H" duration of the clock fluctuates from -4 to +2 machine cycles in the standard clock mode, and fluctuates from -2 to +2 machine cycles in the high-speed clock mode. In the case of negative fluctuation, the frequency does not increase because "L" duration is extended instead of "H" duration reduction. These are value when SCL clock synchronization by the synchronous function is not performed. CCR value is the decimal notation value of the SCL frequency control bits CCR4 to CCR0. 2:Each value of SCL frequency exceeds the limit at VIIC = 4 MHz or more. When using these setting value, use VIIC = 4 MHz or less. Refer to I2 C system clock selection bits (bit 6, 7 of I 2C control register 1) on VIIC. 3:The data formula of SCL frequency is described below: VIIC/(8 X CCR value) Standard clock mode VIIC/(4 X CCR value) High-speed clock mode (CCR value 5) VIIC/(2 X CCR value) High-speed clock mode (CCR value = 5) Do not set 0 to 2 as CCR value regardless of VIIC frequency. Set 100 kHz (max.) in the standard clock mode and 400 kHz (max.) in the high-speed clock mode to the SCL frequency by setting the SCL frequency control bits CCR4 to CCR0.
1 1 1
1 1 1
page 160 of 266
0 1 1
1 0 1
M16C/6KA Group
MULTI-MASTER I2C-BUS Interface
I2C Control Register 0
The I2C control register 0 (address 032316, 033316, 031316) of channel 0, 1 controls data communication format. *Bits 0 to 2: Bit counter (BC0-BC2) These bits decide the number of bits for the next 1-byte data to be transmitted. The I2C interrupt request signal occurs immediately after the number of count specified with these bits (ACK clock is added to the number of count when ACK clock is selected by ACK bit (bit 7 of address 032416, 033416, 031416)) have been transferred, and BC0 to BC2 are returned to "0002". Also when a START condition is detected, these bits become "0002" and the address data is always transmitted and received in 8 bits. *Bit 3: I2C interface enable bit (ES0) This bit enables to use the multi-master I2C-BUS interface. When this bit is set to "0", the interface is disabled and the SDA and the SCL become high-impedance. When the bit is set to "1", the interface is enabled. When ES0 = "0", the following is performed. 1)Set MST = "0", TRX = "0", PIN = "1", BB ="0", AL = "0", AAS = "0", and AD0 = "0", of I 2C status register (Address : 032816, 033816, 031816) 2)Writing data to I2C data shift register (Address : 032016, 033016, 031016) is inhibited. 3)The TOF bit of I2C control register (Address : 032716, 033716, 031716) is cleared to "0" 4)I2C system clock (VIIC) is stopped and the interval counter, flags are initialized. *Bit 4: Data format selection bit (ALS) This bit decides if the recognition of slave address should be processed. When this bit is set to "0", the addressing format is selected, so that address data will be recognized. The transfer will be processed only when a comparison is matched between the salve address and the address data or a general call is received (refer to the item of bit 1 of I2C status register: general call detection flag). When this bit is set to "1", the free data format is selected, so that slave address will not be not recognized. *Bit 5: Addressing format selection bit (DBIT SAD) This bit selects a slave address specification format. When this bit is set to "0", the 7-bit addressing format is selected. In this case, only the high-order 7 bits (slave address) of the I2C address register (address 032216, 033216, 031216) are compared with address data. When this bit is set to "1", the 10-bit addressing format is selected, and all the bits of the I2C address register are compared with address data. *Bit 6: I2C-BUS interface reset bit (IHR) The bit is used to reset I2C-BUS interface circuit in the case that the abnormal communication occurs. When the ES0 bit is"1" (I2C-BUS interface is enabled), writing"1" to the IHR bit makes a H/W reset. Flags are processed as follows: 1)Set MST = "0", TRX = "0", PIN = "1", BB ="0", AL = "0", AAS = "0", and AD0 = "0", of I 2 C status register (Address : 032816, 033816, 031816) 2)The TOF bit of I2C control register (Address : 032716, 033716, 031716) is cleared to "0" 3)The interval counter, flags are initialized. After writing"1" to IHR bit, the circuit reset processing will be finished in Max. 2.5 VIIC cycles and IHR bit will be automatically cleared to "0". Fig.GC-6 shows the reset timing. *Bit 7: I2C-BUS interface pin input level selection bit This bit selects the input level of the SCL and SDA pins of the multi-master I2C-BUS interface. When this bit is set to"1" the P60, P61/P62, P63/P76, P77 will become SMBus input level.
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z page 161 of 266
M16C/6KA Group
MULTI-MASTER I2C-BUS Interface
The signal of writing "1" to IHR bit
IHR bit
The reset signal to I2 C-BUS interface circuit
2.5 VIIC cycles
Fig.GC-6 The timing of reset to the I2C-BUS interface circuit
I 2 C control register 0
b7 b6 b5 b4 b3 b2 b1 b0
Symbol S1Di(i=0,1,2)
Address 032316,033316,031316
When reset 000000002
Bit Symbol
BC0
Bit name
Bit counter (Number of transmitting/ receiving bits) b2 0 0 0 0 1 1 1 1 b1 0 0 1 1 0 0 1 1 b0 0 1 0 1 0 1 0 1 : : : : : : : :
Function
(Note) 8 7 6 5 4 3 2 1
RW
BC1
BC2
ES0
I 2C-BUS interface enable bit
0 : Disable 1 : Enable 0 : Addressing format 1 : Free data format
ALS
Data format selection bit
DBIT SAD
Addressing format selection bit I2 C-BUS interface reset bit
2
0 : 7-bit addressing format 1 : 10-bit addressing format 0 : Release of reset (auto) 1 : Reset 0 : I 2 C-BUS input 1 : SMBUS input
IHR
TISS Note
I C-BUS interface pin input level selection bit
In the following status, the bit counter will be cleared automatically *Start condition/stop condition is detected *Right after the completion of 1 byte data transmission *Right after the completion of 1 byte data receiving
Fig.GC-7 I2C control register
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z page 162 of 266
M16C/6KA Group
MULTI-MASTER I2C-BUS Interface
I2C Status Register
The I2C status register (address 032816, 033816, 031816) controls the I2C-BUS interface status. The loworder 6 bits are read-only if it is used for status check. The high-order 2 bits can be both read and written. Regarding to the function of writing to the low-order 6 bits, refer to the method of start condition/stop condition generation described later. *Bit 0: Last receive bit (LRB) This bit stores the last bit value of received data and can also be used for ACK receive confirmation. If ACK is returned when an ACK clock occurs, the LRB bit is set to "0". If ACK is not returned, this bit is set to "1". Except in the ACK mode, the last bit value of received data is input. The bit will be "0" by executing a write instruction to the I2C data shift register (address 032016, 033016, 031016). *Bit 1: General call detecting flag (AD0) When the ALS bit is "0", this bit is set to "1" when a general call* whose address data is all "0" is received in the slave mode. By a general call of the master device, every slave device receives control data after the general call. The AD0 bit is set to "0" by detecting the STOP condition, START condition, or ES0 is"0", or reset. *General call: The master transmits the general call address "0016" to all slaves. *Bit 2: Slave address comparison flag (AAS) This flag indicates a comparison result of address data when the ALS bit is "0". 1)In the slave receive mode, when the 7-bit addressing format is selected, this bit is set to "1" in one of the following conditions: * The address data, which following the start conduction, is same with upper bits data of I 2C address register(Address 032216, 033216, 031216) * A general call is received. 2)In the slave reception mode, when the 10-bit addressing format is selected, this bit is set to "1" with the following condition: * When the address data is compared with the I2C address register (8 bits consisting of slave address and RBW bit), the first bytes agree. 3)This bit is set to "0" by executing a write instruction to the I2C data shift register (address 032016, 033016, 031016) when ES0 is set to "1". The bit is also set to "0" when ES0 is set to "0" or when reset. *Bit 3: Arbitration lost* detecting flag (AL) In the master transmission mode, when the SDA is made "L" by any other device, arbitration is judged to have been lost, so that this bit is set to "1". At the same time, the TRX bit is set to "0". Immediately after transmission of the byte whose arbitration was lost is completed, the MST bit is set to "0". The arbitration lost can be detected only in the master transmission mode. When arbitration is lost during slave address transmission, the TRX bit is set to "0" and the reception mode is set. Consequently, it becomes possible to detect the agreement between its own slave address and address data transmitted by another master device. The bit is cleared to "0" if writing to I2C data shift register (address 032016, 033016, 031016) when ES0 is "1". The bit is also cleared to "0" when ES0 is set to "0" or when reset. *Arbitration lost: The status in which communication as a master is disabled.
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 163 of 266
M16C/6KA Group
MULTI-MASTER I2C-BUS Interface
*Bit 4: I2C-BUS interface interrupt request bit (PIN) This bit generates an interrupt request signal. After each byte data is transmitted, the PIN bit changes from "1" to "0". At the same time, an I2C interrupt request signal occurs to the CPU. The PIN bit is set to "0" synchronized with the falling edge of the last internal transmitting clock (including the ACK clock) and an interrupt request signal occurs synchronized with the falling edge of the PIN bit. When the PIN bit is "0", the SCL is kept in the "0" state and clock generation is disabled. In the ACK clock enable mode, if WIT bit (bit 1 of I2C control register 1) is set to "1", synchronized with the falling edge of last bit clock and ACK clock, PIN bit becomes to "0" and I2C interrupt request is generated (Refer to the description on bit 1 of I2C control register 1: the data reception completion interrupt enable bit). Fig.GC-9 shows the timing of I2C interrupt request generation. The bit is read-only, the value should be "0" in writing. The PIN bit is set to "0" in one of the following condition: *Executing a write instruction to the I2C data shift register (address 032016, 033016, 031016). *Executing a write instruction to the I2C clock control register (Address : 032416, 033416, 031416) (only when WIT is "1" and internal WAIT flag is "1") *When the ES0 bit is "0" *At reset The PIN bit is set to "0" in one of the following condition: *Immediately after the completion of 1-byte data transmission (including arbitration lost is detected) *Immediately after the completion of 1-byte data reception *In the slave reception mode, with ALS = "0" and immediately after the completion of slave address agreement or general call address reception *In the slave reception mode, with ALS = "1" and immediately after the completion of address data reception *Bit 5: Bus busy flag (BB) This bit indicates the in-use status the bus system. When this bit is set to "0", bus system is not busy and a START condition can be generated. The BB flag is set/reset by the SCL, SDA pins input signal regardless of master/slave. This flag is set to "1" by detecting the start condition, and is set to "0" by detecting the stop condition. The condition of the detecting is set by the start/stop condition setting bits (SSC4-SSC0) of the I2C start/stop condition control register (address 032516, 033516, 031516). When the ES0 bit (bit 3) of the I2C control register (address 032316, 033316, 031316) is "0" or reset, the BB flag is set to "0". For the writing function to the BB flag, refer to the sections "START Condition Generating Method" and "STOP Condition Generating Method" described later. *Bit 6: Communication mode specification bit (transfer direction specification bit: TRX) This bit decides a direction of transfer for data communication. When this bit is "0", the reception mode is selected and the data from a transmitting device is received. When the bit is "1", the transmission mode is selected and address data and control data are output onto the SDA synchronized with the clock generated on the SCL. This bit can be set/reset by software or hardware. This bit is set to "1" by hardware in the following condition: In slave mode with ALS = "0", if the AAS flag is set to "1" after the address data reception and the received ___ R/W bit is "1". This bit is set to "0" by hardware in one of the following conditions: *When arbitration lost is detected. *When a STOP condition is detected. *When a start condition is prevented by the start condition duplication preventing function (Note). *When a start condition is detected with MST = "0". *When ACK non-return is detected with MST = "0". *When ES0 = "0". *At reset
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z page 164 of 266
M16C/6KA Group
MULTI-MASTER I2C-BUS Interface
*Bit 7: Communication mode specification bit (master/slave specification bit: MST) This bit is used for master/slave specification for data communication. When this bit is "0", the slave is specified, so that a START condition and a STOP condition generated by the master are received. The data communication is performed synchronized with the clock generated by the master. When this bit is "1", the master is specified and a START condition and a STOP condition are generated. Additionally, the clocks required for data communication are generated on the SCL. This bit is set to "0" by hardware in one of the following conditions. *Immediately after the completion of 1-byte data transfer when arbitration lost is detected. *When a STOP condition is detected. *Writing a start condition is prevented by the start condition duplication preventing function (Note). *At reset Note: START condition duplication preventing function The MST, TRX, and BB bits is set to "1" at the same time after confirming that the BB flag is "0" in the procedure of a START condition occurrence. However, when a START condition by an other master device occurs and the BB flag is set to "1" immediately after the contents of the BB flag is confirmed, the START condition duplication preventing function makes the writing to the MST and TRX bits invalid. The duplication preventing function becomes valid from the rising of the BB flag to reception completion of slave address. Refer to the method on the start condition generation in detail.
I C status register
b7 b6 b5 b4 b3 b2 b1 b0
2
Symbol S1i(i=0,1,2)
Address 032816,033816,031816
When reset 0001000X2
Bit symbol
LRB AD0 AAS AL PIN BB TRX
Bit name
Last receive bit General call detecting flag Slave address comparison flag Arbitration lost detection flag I 2 C-BUS interface interrupt request bit Bus busy flag Communication mode specification bits
Function
0 : Last bit = "0" 1 : Last bit = "1" 0 : No general call detected 1 : General call detected 0 : Address disagreement 1 : Address agreement 0 : Not detected 1 : Detected 0 : Interrupt request issued 1 : No interrupt request issued 0 : Bus free 1 : Bus busy b7 0 0 1 1 b6 0 : Slave receive mode 1 : Slave transmit mode 0 : Master receive mode 1 : Master transmit mode
RW
(Note1)
(Note1)
(Note1)
(Note1)
(Note2)
(Note1)
(Note3)
MST
(Note3)
Note1.This bit is read only if it is used for the status check. How to write this bit, please refer to start condition/stop condition generating method. Note2.The bit can be read and only can be written with "0" by software. Note3.Refer to the method of start condition generation on how to write these bits. How to write this bit, please refer to start condition/stop condition generating method.
Fig.GC-8 I2C status register
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z page 165 of 266
M16C/6KA Group
MULTI-MASTER I2C-BUS Interface
SCL
PIN flag
I2CIRQ
Fig.GC-9 Interrupt request signal generating timing
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 166 of 266
M16C/6KA Group
MULTI-MASTER I2C-BUS Interface
I2C0, I2C1 control register 1
I2C control register 10, 11, 12 (address 032616, 033616, 031616) controls I2C-BUS interface circuit. *Bit 0 : Interrupt enable bit by STOP condition (SIM ) It is possible for I2C-BUS interface to request an interrupt by detecting a STOP condition. If the bit set to "1", an interrupt from I2C-BUS interface occurs by detecting a STOP condition ( There is no change for PIN flag) *Bit 1: Interrupt enable bit at the completion of data receiving (WIT) When with-ACK mode (ACK bit = "1") is specified, by enabling the interrupt at the completion of data receiving (WIT bit = "1"), the I2C interrupt request occurs and PIN bit becomes "0" synchronized with the falling edge of last data bit clock. SCL is fixed "L" and the generation of ACK clock is suppressed. Table GC-3 and Fig.GC-10 show the I2C interrupt request timing and the method of communication restart. After the communication restart, synchronized with the falling edge of ACK clock, PIN bit becomes to "0" and I2C interrupt request occurs. Table.GC-3 Timing of interrupt generation in data receiving The timing of I2C interrupt generation (1) Synchronized with the falling edge of the last data bit clock (2) Synchronized with the falling edge of the ACK clock The method of communication restart The execution of writing to ACKBIT of I2C clock control register. (Do not write to I2C data shift register. The processing of ACK clock would be incorrect.) The execution of writing to I2C data shift register
The state of internal WAIT flag can be read out by reading the WIT bit. The internal WAIT flag is set after writing to I2C data shift register, and it is reset after writing to I2C clock control register. Consequently, which of the timing 1) and 2) of interrupt request occurring can be understood. (See Fig.GC-10)In the cases of transmission and address data reception immediately after the START condition, the interrupt request only occurs at the falling edge of ACK clock regardless of the value of WIT bit and the WAIT flag remains the reset state. Write "0" to WIT bit when in NACK is specified. (ACK bit = "0")
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 167 of 266
M16C/6KA Group
MULTI-MASTER I2C-BUS Interface
*Bits 2, 3 : Port function selection bits PED, PEC When ES0 bit of I2C control register 0 is set to "1", P61/P63/P77 and P60/P62/P76 function as SCL and SDA respectively. However, if PED is set to "1", SDA functions as output port so as to SCL if PEC is set to "1". In this case, if "0" or "1" is written to the port register, the data can be output on to the I2C-BUS regardless of the internal SCL/SDA output signals. The functions of SCL/SDA are returned back by setting PED/PEC to "1" again. If the ports are set in input mode, the values on the I2C-BUS can be known by reading the port register regardless of the values of PED and PEC.Table GC-4 shows the port specification. Table.GC-4 Ports specifications Pin name P60/P62/P76 ES0 bit 0 1 1 ES0 bit 0 1 1 PED bit 0 1 PEC bit 0 1
P6/P7 port direction register
Function Port I/O function SDA I/O function SDA input function, port output function Function Port I/O function SCL I/O function SCL input function, port output function
0/1 P6/P7 port direction register
P61/P63/P77
0/1 -
*Bits 4, 5 : SDA/SCL logic output value monitor bits SDAM /SCLM It is possible to monitor the logic value of the SDA and SCL output signals from I2C-BUS interface circuit. SDAM can monitor the output logic value of SDA. SCLM can monitor the output logic value of SCL. The bits are read-only. Write "0" if in writing (Writing "1" is reserved) *Bits 6, 7 : I2C system clock selection bits ICK0, ICK1 These bits select the basic operation clock of I2C-BUS interface circuit. It is possible to select I2C system clock VIIC among 1/2,1/4 and 1/8 of main clock f(XIN) and 1/2 of external I2C clock (ICCK) Table.GC-5 I2C system clock selecting bits ICK1 ICK0 I2C system clock 0 0 VIIC = 1 / 2f1 0 1 VIIC = 1 / 4f1 1 0 VIIC = 1 / 8f1 1 1 VIIC = 1 / 2ICCK Note: f1 = f(XIN) ICCK = External I2C clock
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 168 of 266
M16C/6KA Group
MULTI-MASTER I2C-BUS Interface
*The address reception in STOP mode /WAIT mode It is possible for I2C-BUS interface to receive address data even in STOP mode or in WAIT mode. However the I2C system clock VIIC should be supplied. Table.GC-6 shows the setting list. Table.GC-6 Clock setting to the I2C system in different operation mode. Mode STOP mode WAIT mode The setting content The external clock is selected as the I2C system clock ( ICK1 = 1, ICK0 = 1) and the external I2C clock is supplied by ICCK. The external clock is selected as the I2C system clock ( ICK1 = 1, ICK0 = 1) and the external I2C clock is supplied by ICCK. Select the peripheral function clock stop bit CMO2 (bit 2 of the system clock control register 0, address : 000616) to the state of not stopping f1,f8,f32 (CMO2 = 0) when in WAIT mode, and then execute the WAIT command. The external clock is selected as the I2C system clock ( ICK1 = 1, ICK0 = 1) and the external I2C clock is supplied by ICCK.
Low power consumption mode
When in reception mode, ACK bit = "1" WIT bit = "0"
SCL SDA ACKBIT PIN flag Internal WAIT flag I2C interrupt request signal The writing signal of I2C data shift register 7 clock 7 bit 8 bit 8 clock ACK clock ACK bit 1 clock 1 bit
When in reception mode, ACK bit = "1" WIT bit = "1"
SCL SDA ACKBIT PIN flag Internal WAIT flag I2C interrupt request signal The writing signal of I2C data shift register The writing signal of I2C clock control register 7 clock 7 bit 8 bit 8 clock ACK clock 1 bit
(1)
(2)
Note. Do not write to I2C clock control register except bit ACKBIT.
Fig.GC-10 The timing of the interrupt generation at the completion of data reception
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 169 of 266
M16C/6KA Group
MULTI-MASTER I2C-BUS Interface
I C control register 1
b7 b6 b5 b4 b3 b2 b1 b0
2
Symbol S3Di(i=0,1,2)
Address 032616,033616,031616
When reset 001100002
Bit Symbol
SIM
Bit name
The interrupt enable bit of STOP condition detection
Function
0 : Disable the interrupt of STOP condition detection 1 : Enable the interrupt of STOP condition detection 0 : Disable 1 : Enable When in NACK setting (ACK bit = "0") please write "0"
RW
WIT
The interrupt enable bit of at the completion of data reception
PED
SDAi/Port function switching bit
0 : SDA I/O pin(enable ES0 = 1) 1 : GPIO(enable ES0 = 1)
PEC
SCLi/Port function switching bit The logic value monitor bit of SDA output The logic value monitor bit of SCL output I 2 C system clock selection bits
0 : SCL I/O pin(enable ES0 = 1) 1 : GPIO(enable ES0 = 1) 0 : SDA output logic value = "0" 1 : SDA output logic value = "1" 0 : SCL output logic value = "0" 1 : SCL output logic value = "1" b7 b6 0 0 : VIIC=1/2f1 0 1 : VIIC=1/4f1 f1=f(XIN) 1 0 : VIIC=1/8f1 1 1 : VIIC=1/2ICCK ICCK=External I2C clock
SDAM
SCLM ICK0
ICK1
Fig.GC-11 I2C control register 1
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 170 of 266
M16C/6KA Group
MULTI-MASTER I2C-BUS Interface
I2C control register 2
I2C0, 1 control register 2 (address: 032716, 033716, 031716) control the detection of communication abnormality. In I2C-BUS communication, the data transfer is controlled by the SCL clock signal. The devices will stop in the communication state if SCL stops during transfer. So if the SCL clock stops in "H" state for a period of time, the I2C-BUS interface circuit can detect the time out and request an I2C interrupt. Please see Fig.GC-12.
SCL clock stop ("H") SCL SDA BB flag Internal counter start signal Internal counter stop, reset signal The time of timeout detection Internal counter overflow signal I2C interrupt request signal 1 bit 1 clock 2 bit 2 clock 3 bit 3 clock
Fig.GC-12 The timing of timeout detection *Bit0: Time out detection function enable bit (TOE) The bit enables timeout detection function. By setting this bit to "1", the I2C interrupt request signal will be generated if the SCL clock stops in "H" state for a period of time during bus busy (BB flag ="1"). The time of time out detection which is selected by timeout detection time selection bit (TOSEL) with long time mode or short time mode will be calculated by internal counter. When time out is detected, please set "0" to I2C-BUS interface enable bit (ES0) and then process initialization. *Bit1: Time out detection flag (TOF ) The bit is the flag showing timeout detection status. If the time which is calculated by the internal counter overflows, the time out detection flag (TOF) becomes to "1", and at the same time the I2C interrupt request signal is generated. *Bit2: timeout detection time selection bit (TOSEL) The bit selects timeout detection time from long time and short time mode. If TOSEL = "0", the long time mode; TOSEL = "1", the short mode is selected respectively. The long time is up counted by 16 bits counter and the short time is up counted by 14 bits counter based on I2C system clock (VIIC). Table GC-7 shows examples of the timeout detection time. Table.GC-7 Examples of timeout detection time VIIC(MHz) 4 2 1 Long time mode 16.4 32.8 65.6 (Unit: ms) Short time mode 4.1 8.2 16.4
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 171 of 266
M16C/6KA Group
MULTI-MASTER I2C-BUS Interface
I C control register 2
b7 b6 b5 b4 b3 b2 b1 b0
2
Symbol S4Di(i=0,1,2)
Address 032716,033716,031716
When reset 000000002
Bit symbol
TOE TOF TOSEL
Bit name
Timeout detection function enable bit Timeout detection flag Timeout detection time selection bit
Function
0 : Disable 1 : Enable 0 : Not detected 1 : Detected 0 : Long time 1 : Short time
R
W
Nothing is assigned. Can not be written in the value is "0" SCPIN STOP condition detection interrupt request bit 0 : No interrupt request 1 : Interrupt request
Fig.GC-13 I2C control register 2 *Bit7: STOP condition detection interrupt request bit (SCPIN) The bit monitors the stop condition detection interrupt. The bit becomes to "1" when I2C-BUS interface interrupt is generated by the detecting of STOP condition. Writing "0" clears the bit and "1" can not be written.
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 172 of 266
M16C/6KA Group
MULTI-MASTER I2C-BUS Interface
I2C START/STOP condition control register
I2C START/STOP condition register(address 032516, 033516, 031516) controls the detection of START/STOP condition. *Bit0-Bit4: START/STOP condition setting bits (SSC4-SSC0) Because the release time, set up time and hold time of SCL is calculated on the base of I2C system clock(VIIC). The detecting condition changes depending on the oscillation frequency and I2C system clock selecting bits. It is necessary to set the suitable value of START/STOP condition setting bits (SSC4-SSC0) so that obtain the release time, set up time and hold time corresponding to the system clock frequency. Refer to Table GC-11. Do not set odd number or "000002" to START/STOP condition setting bits. The recommended setting value to START/STOP condition setting bits (SSC4-SSC0) at each oscillation frequency under standard clock mode is shown in Table. GC-8. The detection of START/STOP condition starts immediately after the setting of ES0=1. *Bit5: SCL/SDA interrupt pin polarity selection bit (SIP) The interrupt can be generated by detecting the rising edge or the falling edge of SCL pin or SDA pin. SCL/SDA interrupt pin polarity selection bit selects the polarity of SCL pin or SDA pin for interrupt. *Bit6 : SCL/SDA interrupt pin selection bit (SIS) SCL/SDA interrupt pin selection bit selects either SCL pin or SDA pin as SCL/SDA interrupt enable pin. Note: The SCL/SDA interrupt request may be set when the setting of I2C-BUS interface enable bit ES0 changes. Thus set the interrupt disable before the setting of SCL/SDA interrupt pin polarity selection bit (SIP) and SCL/SDA interrupt selection bit(SIS). After that reset "0" to the interrupt request bit before enabling the interrupt. *Bit7: START/STOP condition generation selecting bit (STSPSEL) The bit selects the length of set up/hold time when START/STOP condition occurs. The length of set up/hold time is based on the I2C system clock cycles. Refer to Table GC-9. Set the bit to "1" if I2C system clock frequency is over 4MHz.
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 173 of 266
M16C/6KA Group
MULTI-MASTER I2C-BUS Interface
I C start/stop condition control register
b7 b6 b5 b4 b3 b2 b1 b0
2
Symbol S2Di(i=0,1,2)
Address 032516,033516,031516
When reset 000110102
Bit Symbol
SSC0 SSC1 SSC2 SSC3 SSC4
Bit name
START/STOP condition setting bits
Function
The setting of the detecting condition of START/STOP condition.Refer to Table GC-8. Note: Prohibit the setting of "000002" and odd value
RW
SIP
SCL/SDA interrupt pin polarity selection bit SCL/SDA interrupt pin selection bit START/STOP condition generation selection bit
0 : Active in falling edge 1 : Active in rising edge 0 : SDA enable 1 : SCL enable 0 : Setup/hold time short mode 1 : Setup/hold time long mode
SIS
STSP SEL
Fig.GC-14 I2C start/stop condition control register
Table.GC-8 Recommended setting value (SSC4 - SSC0) start/stop condition at each oscillation frequency Oscillation f(XIN) (MHz) 10 8 8 4 2
I2C system clock selection
1 / 2f1 1 / 2f1 1 / 8f1 1 / 2f1 1 / 2f1
I2C system SSC4-SSC0 clock(MHz) 5 XXX11110 4 XXX11010 XXX11000 1 XXX00100 2 XXX01100 XXX01010 1 XXX00100
SCL release time(cycle) 6.2s (31) 6.75s(27) 6.25s(25) 5.0s (5) 6.5s (13) 5.5s (11) 5.0s (5)
Setup time (cycle) 3.2s (16) 3.5s (14) 3.25s(13) 3.0s (3) 3.5s (7) 3.0s (6) 3.0s (3)
Hold time (cycle) 3.0s (15) 3.25s(13) 3.0s (12) 2.0s (2) 3.0s (6) 2.5s (5) 2.0s (2)
Note: Do not set odd value or "000002" to START/STOP condition setting bits.
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 174 of 266
M16C/6KA Group
MULTI-MASTER I2C-BUS Interface
START Condition Generation Method
When ES0 bit of the I2C control register is "1" and the BB flag of I2C status register is "0", writing "1" to the MST, TRX, and BB bits and "0" to the PIN and low-order 4 bits of the I2C status register (address 032816, 033816, 031816) simultaneously enters the standby status to generate the start condition. The start condition is generated after writing slave address data to the I2C data shift register. After that, the bit counter becomes "0002" and 1 byte SCL are output. The START condition generation timing is different in the standard clock mode and the high-speed clock mode. Refer to Fig.GC-17 the START condition generation timing diagram, and Table GC-9 the START condition generation timing table.
Interrupt disable
No BB=0?
Yes S1i=E016 Start condition standby status setting
S0i=Data
Start condition trigger occur. Data=Slave address data
Interrupt enable
Fig.GC-15 Start condition generation flow chart
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 175 of 266
M16C/6KA Group
MULTI-MASTER I2C-BUS Interface
Function of protection of duplicate START condition
It is necessary to verify that the bus is not in use via BB flag before setting up a START condition. However, there is a possibility that right after the verification of BB flag, the BB flag becomes to "1" because a START condition is generated by another master device .In this case, the function to interrupt the start condition is built in. When the function starts, it works as follows: *The prohibition of setting up START condition standby If the START condition standby has been set up, releases it and resets the bits of MST and TRX. *The prohibition of writing to the I2C data shift register (The prohibition of generating a START condition trigger) *If the generation of start condition is interrupted, sets the AL flag. The function of protection of duplicate START condition is valid from the falling edge of SDA of START condition to the completion of slave reception. Fig.GC-16 shows the valid period of the function of protection of duplicate START condition.
SCL SDA BB flag 1 bit
1 clock
2 clock 2 bit
3 clock 3 bit
8 clock 8 bit
ACK clock
ACK bit
The valid period of protection of duplicate START condition
Fig.GC-16 The valid period of the function of protection of duplicate START condition
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 176 of 266
M16C/6KA Group
MULTI-MASTER I2C-BUS Interface
STOP Condition Generation Method
When the ES0 bit of the I2C control register is "1", writing "1" to the MST and TRX bits, and "0" to the BB, PIN and low-order bits of the I2C status register simultaneously enters the standby status to generate the stop condition. The stop condition is generated after writing dummy data to the I2C data shift register. The STOP condition generation timing is different in the standard clock mode and the high-speed clock mode. Refer to Fig.GC-18, the STOP condition generation timing diagram, and Table GC-9, the STOP condition generation timing table. Do not write data to I2C status register and I2C data shift register, before BB flag becomes to "0" after the instruction to generate the stop condition to avoid the influence on generating STOP condition waveform.
I2C data shift register write signal
SCL SDA
Setup time
Hold time
Fig.GC-17 Start condition generation timing diagram
I2C data shift register write signal
SCL SDA
Setup time
Hold time
Fig.GC-18 Stop condition generation timing diagram Table.GC-9 Start/Stop generation timing table Start/Stop condition generation selection bit Setup "0" time "1" hold "0" time "1" Note: VIIC = 4MHz Item Standard clock mode 5.0s (20 cycle) 13.0s (52 cycle) 5.0s (20 cycle) 13.0s (52 cycle) High-speed clock mode 2.5s (10 cycle) 6.5s (26 cycle) 2.5s (10 cycle) 6.5s (26 cycle)
As mentioned above, Writing "1" to MST and TRX bits. Writing "1" or "0" to BB bit, writing "0" to PIN and low-order 4 bits, simultaneously sets up the START or STOP condition standby. It releases SDA in START condition standby, makes SDA to "L" in STOP condition standby. The signal of writing to data shift register triggers the generation of START/STOP condition. In the case of setting MST, and TRX to "1" but do not want to generate a START/STOP condition. Write "1" to the low-order 4 bits simultaneously. Fig.GC-10 illustrates the function of writing to status register. Table.GC-10 The function of writing to status register The value of the data writing to status register MST TRX BB PIN AL AAS AS0 LRB 1 1 1 0 0 0 0 0 1 1 0 0 0 0 0 0 0/1 0/1 0 1 1 1 1
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z page 177 of 266
Function
Setting up the START condition stand by in master transmission mode Setting up the STOP condition stand by in master transmission mode Setting up the communication mode (refer to the description on I2C status register)
M16C/6KA Group
MULTI-MASTER I2C-BUS Interface
START/STOP Condition Detecting Operation
The START/STOP condition detection operations are shown in Fig.GC-19, GC-20 and Table.GC-11 The START/STOP condition is set by the START/STOP condition set bit. The START/STOP condition can be detected only when the input signal of the SCL and SDA pins satisfy with three conditions: SCL release time, setup time, and hold time (see Table.GC-11). The BB flag is set to "1" by detecting the START condition and is reset to "0" by detecting the STOP condition. The BB flag set/reset timing is different in the standard clock mode and the high-speed clock mode. Refer to Table GC-11, the BB flag set/reset time.
SCL release time
SCL SDA
Setup time
Hold time
BB flag set time
BB flag
Fig.GC-19 Start condition detection timing diagram
SCL release time
SCL SDA
Setup time
Hold time
BB flag reset time
BB flag
Fig.GC-20 Stop condition detection timing diagram
Table.GC-11 Start/Stop generation timing table SCL release time Setup time Hold time BB flag set/reset time Standard clock mode SSC value + 1 cycle (6.25s) SSC value + 1 cycle < 4.0s (3.25s) 2 SSC value cycle < 4.0s (3.0s) 2 SSC value - 1 +2 cycle (3.375s) 2 High-speed clock mode 4 cycle (1.0s) 2 cycle (0.5s) 2 cycle (0.5s) 3.5 cycle (0.875s)
Note: Unit : Cycle number of system clock VIIC SSC value is the decimal notation value of the START/STOP condition set bits SSC4 to SSC0. Do not set "0" or an odd number to SSC value. The value in parentheses is an example when the I2C START/STOP condition control register is set to "1816" at VIIC = 4 MHz.
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 178 of 266
M16C/6KA Group
MULTI-MASTER I2C-BUS Interface
Address Data Communication
There are two address data communication formats, namely, 7-bit addressing format and 10-bit addressing format. The respective address communication formats are described below. (1) 7-bit addressing format To adapt the 7-bit addressing format, set the DBIT SAD bit of the I2C control register 0 (address 032316, 033316, 031316) to "0". The first 7-bit address data transmitted from the master is compared with the highorder 7-bit slave address stored in the I2C address register (address 032216, 033216, 031216). At the time of this comparison, address comparison of the RBW bit of the I2C address register (address 032216, 033216, 031216) is not performed. For the data transmission format when the 7-bit addressing format is selected, refer to Fig.GC-21 (1) and (2). (2) 10-bit addressing format To adapt the 10-bit addressing format, set the DBIT SAD bit of the I2C control register 0 (address 032316, 033316, 031316) to "1". Also set the WIT bit of I2C control register 1 to "1". An address comparison is performed between the first-byte address data transmitted from the master and the 8-bit slave address stored in the I2C address register (address 032216, 033216, 031216). At the time of this comparison, an address ____ comparison between the RBW bit of the I2C address register (address 032016, 033016, 031016) and the R/W bit which is the last bit of the address data transmitted from the master is made. In the 10-bit addressing mode, the RBW bit which is the last bit of the address data not only specifies the direction of communication for control data, but also is processed as an address data bit. When the first-byte address data agree with the slave address, the AAS bit of the I2C status register (address 032816, 033816, 031816) is set to "1". After the second-byte address data is stored into the I2C data shift register (address 32016, 33016, 031016), perform an address comparison between the second-byte data and the slave address by software. When the address data of the 2 bytes agree with the slave address, write "0" to the ACKBIT to I2C clock control register, to return an ACK. When the address data of the 2 bytes do not agree with the slave address, it does not return an ACK so that makes the finish of the communication by writing "1" to the ACKBIT. If the address data agree with each other, set the RBW bit of the I2C address register (address 032216, 033216, 031216) to "1" by software. This processing can make the 7-bit slave ___ address and R/W data agree, which are received after a RESTART condition is detected, with the value of the I2C address register (address 032216, 033216, 031216). For the data transmission format when the 10-bit addressing format is selected, refer to Fig.GC-21(3) and (4).
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 179 of 266
M16C/6KA Group
MULTI-MASTER I2C-BUS Interface
(1) A master-transmitter transmits data to a slave-receiver
S
Slave address 7 bits
R/W "0"
A
Data
1 - 8 bits
A
Data
1 - 8 bits
A/A
P
(2) A master-receiver receives data from slave-transmitter
S
Slave address 7 bits
R/W "1"
A
Data
1 - 8 bits
A
Data
1 - 8 bits
A
P
(3) A master-transmitter transmits data to a slave-receiver with a 10-bit address
S
Slave address 1 st 7 bits 7 bits
R/W "0"
A
Slave address 2nd byte 8 bits
A
Data
1 - 8 bits
A
Data
1 - 8 bits
A/A
P
(4) A master-receiver receives data from slave-transmitter with a 10-bit address
S
Slave address 1 st 7 bits 7 bits
R/W "0"
A
Slave address 2nd byte 8 bits
A
Sr
Slave address 1 st 7 bits 7 bits
R/W "1"
A
Data
1 - 8 bits
A
Data
1 - 8 bits
A
P
S : START condition A : ACK bit Sr : Restart condition
P : STOP condition R/W : Read/Write bit
Fig.GC-21 Address data communication format
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 180 of 266
M16C/6KA Group
MULTI-MASTER I2C-BUS Interface
Example of Master Transmission
An example of master transmission in the standard clock mode, at the SCL frequency of 100 kHz and in the ACK return mode is shown below. 1)Set a slave address in the high-order 7 bits of the I2C address register and "0" into the RBW bit. 2)Set the ACK return mode and SCL = 100 kHz by setting "0016" in the I2C control register 1 and "8516" in the I2C clock control register respectively. (f(XIN)=8MHz) 3)Set "0016" in the I2C status register so that transmission/reception mode is initialized. 4)Set a communication enable status by setting "0816" in the I2C control register 0. 5)Confirm the bus free condition by the BB flag of the I2C status register. 6)Set "E016" in the I2C status register to setup a standby of START condition. 7)Set the destination address data for transmission in high-order 7 bit of I2C data shift register and set "0" in the least significant bit. And then a START condition occurs. At this time, SCL for 1 byte and an ACK clock automatically generate. 8)Set transmission data in the I2C data shift register. At this time, an SCL and an ACK clock automatically generate. 9)When transmitting control data of more than 1 byte, repeat step 8). 10)Set "C016" in the I2C status register to setup a STOP condition if ACK is not returned from slave reception side or transmission ends. 11)A STOP condition occurs when writing dummy data to I2C data shift register.
Example of Slave Reception
An example of slave reception in the high-speed clock mode, at the SCL frequency of 400 kHz, in the ACK return mode and using the addressing format is shown below. 1)Set a slave address in the high-order 7 bits of the I2C address register and "0" in the RBW bit. 2)Set the ACK clock mode and SCL = 400 kHz by setting "0016" in the I2C control register 1 and "A516" in the I2C clock control register respectively. (f(XIN)=8MHz) 3)Set "0016" in the I2C status register so that transmission/reception mode is initialized. 4)Set a communication enable status by setting "0816" in the I2C control register 0. 5)When a START condition is received, an address comparison is performed. 6)*When all transmitted addresses are "0" (general call): AD0 of the I2C status register is set to "1" and an interrupt request signal occurs. *When the transmitted addresses agree with the address set in1): ASS of the I2C status register is set to "1" and an interrupt request signal occurs. *In the cases other than the above AD0 and AAS of the I2C status register are set to "0" and no interrupt request signal occurs. 7)Set dummy data in the I2C data shift register. 8)After receiving 1 byte data, it returns an ACK automatically and an interrupt request signal occurs. 9)In the case of whether returning an ACK or not by the content of the received control data, set the WIT bit of I2C control register 1 to "1", and after writing dummy data to I2C data shift register, receives the control data. 10)After receiving 1 byte data, an interrupt request signal occurs, set the ACKBIT to "1" or "0" by reading the content of the data shift register, and then returns or does not return an ACK. 11)When receiving control data of more than 1 byte, repeat step 7) 8) or 7) 10). 12)When a STOP condition is detected, the communication ends.
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 181 of 266
M16C/6KA Group
MULTI-MASTER I2C-BUS Interface
Usage precautions
(1) Access to the registers of I2C-BUS interface circuit The precaution of read/write to the control registers of I2C-BUS circuit is as follows. *I2C data shift register (S0i : 032016, 033016, 031016) Do not write the register during transfer. The transfer bit counter will be reset and makes data communication incorrect. *I2C address register (S0Di : address 032216, 033216, 031216) After the detection of a STOP condition, RBW is reset by H/W. Do not read/write the register at the time, because data may become undetermined. Fig.GC-22 shows the RBW bit H/W reset timing. 2C control register 0 (S1Di : address 032316, 033316, 031316). *I After the detection of a START condition or the completion of 1 byte transfer, bit counter (bits BC0 - BC2) is reset by H/W. Do not read/write the register at the time, because data may become undetermined. Fig.GC-23, GC-24 show the bit counter H/W reset timing. 2C clock control register (S2i : address 032416, 033416, 031416) *I Do not write to this register except ACKBIT during transfer. The I2C clock generator will be reset and *I2C makes transfer incorrect. control register 1 (S3Di : address 032616, 033616, 031616) Write I2C system clock selection bits when I2C-BUS interface enable bit (ES0)is in disable state. By reading the data reception completion interrupt enable bit (WIT), the internal WAIT flag will be read. Thus, do not use bit manipulation (read-modify-write instruction) to access the register. 2C status register (S1i : address 032816, 033816, 031816) *I Do not use bit manipulation (read-modify-write instruction) to access the register because all bits of this register are changed by H/W. Do not read/write during the timing when communication mode setting bits MST and TRX are changed by H/W. Data may become undetermined. Fig.GC-22, GC-23, and GC-24 show the change timing of MST and TRX bits by H/W.
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 182 of 266
M16C/6KA Group
MULTI-MASTER I2C-BUS Interface
SCL SDA BB flag Bit reset signal Related bits RBW MST TRX 1.5VIIC cycle
Fig.GC-22 The timing of bit reset (The detection of STOP condition)
SCL SDA BB flag Bit reset signal Related bits BC0 - BC2 TRX(slave mode)
Fig.GC-23 The timing of bit reset (The detection of START condition)
SCL PIN bit Bit reset signal Bit set signal
2VIIC cycle The bits referring to set 1VIIC cycle TRX(ALS="0" meanwhile the slave reception R/W bit = "1" The bits referring to reset BC0 - BC2 MST(When in arbitration lost) TRX(When in NACK reception in slave transmission mode)
Fig.GC-24 Bit set/reset timing ( at the completion of data transfer)
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 183 of 266
M16C/6KA Group
MULTI-MASTER I2C-BUS Interface
(2) Generation of RESTART condition After 1 byte data transfer, a RESTART condition standby can be set up by writing "E016" to I 2C status register and the SDA pin will be released. Wait in software until SDA become "H" stable and then owing to writing to I2C data shift register a START condition trigger will be generated. Fig.GC-25 shows the restart condition generation timing.
SCL SDA
8 clock
ACK clock
S1i writing signal ( Set the standby of start condition) S0i writing signal (START condition trigger generation)
Insert software wait
Fig.GC-25 The time of generation of RESTART condition
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 184 of 266
M16C/6KA Group
PS2 Interface
PS2 Interface
PS2 interface is supported by 3 channels of serial transmission/reception circuit which is based on PS2 standard specifications. There are two signal lines, used by PS2 interface : PS2 data(DAT) and PS2 clock(CLK). The DAT and CLK signal lines are bidirection and should be connected to positive power supply via external pull-up resistors. These two pins are N-channel open drain output. While bus is released, the states of DAT and CLK is "High". Fig.GK-1 shows the system configuration.
Output
Output
DAT Input Input
DAT
Output
Output
CLK Input Input
CLK
Control side
Device side
Fig.GK-1 System configuration
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 185 of 266
M16C/6KA Group
PS2 Interface
The PS2 interface performs 1 byte data transfer with the format shown in Fig.GK-2. Table GK-1 shows the communication specification.
Table GK-1 Communication specification Item Data transfer format *Start bit *Data bit *Parity bit *Stop bit Transfer clock Reception start condition
Specification : 1 bit : 8 bits (LSB first) : 1 bit (Odd) : 1 bit
Transmission start condition
Transfer abort
Interrupt request generation timing Error detection
Selection function
*Acknowledge : 1 bit (Transmission only) *Using the clock, which is synchronized with the sampling clock of PS2 clock (CLK) *The following conditions should be met for reception start 1) Setting reception enable bit to "1" 2) The detection of "L" on both PS2 clock (CLK) and PS2 data (DAT) lines *The following conditions should be met for transmission start 1) Setting transmission data to PS2i shift register 2) Setting transmission enable bit to "1" *The following conditions should be met for transfer abort 1) Setting transfer interruption bit to "1" 2) The transfer completion flag becomes "1" *In reception: At the completion of stop bit reception *In transmission: At the completion of ACK bit reception. *In transfer interruption: At the completion of transfer interruption *Parity error (In reception) It occurs when there is a parity error in data reception *Framing error (In reception) It occurs when the detection of stop bit of reception data fails. *Abnormal acknowledge reception (In transmission) It occurs when NAK is received from a device side after the data transmission *Sampling clock selection Selecting the clock which samples the PS2 clock (CLK) and PS2 data (DAT)
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 186 of 266
M16C/6KA Group
PS2 Interface
In reception Data :8-bit Parity :Odd Stop :1 bit
START D0 D1
10-bit
D2
D3
D4
D5
D6
D7
PARITY
STOP
1 byte data format
In Transmission Data Parity Stop Acknowledge
START
:8-bit :Odd :1 bit :1 bit
D1
11-bit
D0
D2
D3
D4
D5
D6
D7
PARITY
STOP ACK/NAK
1 byte data format
Fig.GK-2 1 byte data format
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 187 of 266
M16C/6KA Group
PS2 Interface
Fig.GK-3 shows the PS2 interface overall block diagram. Fig.GK-4 shows the transmission/reception block diagram.
Internal data bus
PS2 mode register (02AC16)
Pin selection Control stop
PS2Bi(i=0-2) CLK output DAT output "1" "1"
Ch0
Transmission/ reception section
Interrupt request 0
PS2Ai(i=0-2)
CLK input DAT input
Ch1 "1" "1" Port control section
Transmission/ reception section
Interrupt request 1
f1 Divider
1/4 1/8 1/16 1/32
Sampling clock selection Sampling clock
Ch2
Transmission/ reception section
Interrupt request 2
Fig.GK-3 PS2 interface block diagram
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 188 of 266
M16C/6KA Group
PS2 Interface
Internal data bus PS2i shift register (02A016,02A416,02A816) DAT output Sampling clock CLK output CLK input
Synchronization Reception start detection circuit Transmission/reception control circuit
Reception process section * Completion detection * Parity generation
DAT input
Reception completion PE & FE Transfer completion process circuit
Shift enable
Reception enable
Transfer abort Transmission enable
Transmission process section Completion detection * Parity generation * Acknowledge reception
Transmission completion Acknowledge result
Communication status flags Error flag refresh
Transfer completion flag refresh
All bits clear Interrupt request PS2i control register (02A216,02A616,02AA16) Internal data bus PS2i status register (02A116,02A516,02A916)
Fig.GK-4 Transmission/reception section block diagram (One channel)
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 189 of 266
M16C/6KA Group
PS2 Interface
(1) Register description
q PS2i shift register * Transmission/reception data (1) Data reception The reception data are stored. (2) Data transmission By writing the transmitted data to the register, data transmission is ready to start. PS2 data (DAT) will become "L" automatically (transmission start).
PS2i Shift register
b7 b6 b5 b4 b3 b2 b1 b0
symbol PS20SR PS21SR PS22SR
Address 02A016 02A416 02A816
Reset value 0016 0016 0016
Bit symbol
Bit name
Function Transmission/reception data
RW
Fig.GK-5 PS2i shift register
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 190 of 266
M16C/6KA Group
PS2 Interface
q PS2i Control register * Reception enable bit (REN) The data reception is allowed when this bit is set to "1". The PS2 clock (CLK) will become to "H" (reception enable status) automatically. This bit will be cleared to "0" automatically after the completion of data reception and PS2 clock (CLK) will become "L" (reception disable status) . If this bit is needed wants to be cleared after setting it to "1" but before the transfer completion flag is set, set reception enable bit = "0", transfer abort request bit = "0" and process the transfer abort simultaneously. * Transmission enable bit (TEN) After writing transmission data to the PS2i shift register, setting the bit to "1" makes data transmission enabled and PS2 clock (CLK) will become "H" automatically (transmission enable status). This bit will be cleared to "0" automatically after the completion of data transmission and PS2 clock (CLK) will become "L" (transmission disable status). If this bit is needed to be cleared after setting it to "1" but before the transfer completion flag is set, set reception enable bit = "0", transfer abort request bit = "0" and process the transfer abort simultaneously. * Transfer abort request bit (RSTOP) This bit is used to abort the data transfer procession. At the completion of transfer abort procession, the transfer completion flag and transfer abort flag of PS2i status register are set to "1", the bit is cleared to "0" automatically and PS2 clock (CLK) will become "L" ( reception disable status). After "L" is output to the PS2 clock (CLK), do not execute the following transmission/reception before the device recognizes the transfer abort request.
PS2i control register
b7 b6 b5 b4 b3 b2 b1 b0
Symbol PS20CON PS21CON PS22CON
Address 02A216 02A616 02AA16
Reset Value 0016 0016 0016
Bit Symbol
REN TEN RSTOP
Bit name
Reception enable bit Transmission enable bit Transfer abort request bit
Function
0 : Disable 1 : Enable 0 : Disable 1 : Enable 0 : No transfer abort 1 : Transfer abort
RW
Nothing is assigned. Meaningless in writing, "0" in reading.
Fig.GK-6 PS2i control register
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 191 of 266
M16C/6KA Group
PS2 Interface
qPS2i status register * Transfer completion flag (TI) The flag is set to "1" at the completion of transmission/reception and the completion of transfer abort. The flag is cleared at read out from PS2i shift register or when the reception enable bit is changed from "0" to "1". * Receiving flag (RF) The flag is set to "1" during the data reception. The flag is cleared automatically after the data reception or after the transfer abort. * Reception abort incognizable flag (CD) The flag is set in the case that device side can not recognize the abort even if the reception abort is requested. (The flag is set in the period between the completion of data bit 6 reception and the completion of stop bit reception.) The flag is cleared automatically after the completion of data reception or after the completion of transfer abort. Note that during the period when the flag is set, the device side can not recognize the reception abort request even if the transfer abort is executed. Thus the data that the transfer abort is requested will not be resent from device side. * Transfer status flag (TS) The flag is set to "1" at the completion of data reception. The flag is cleared at read out from PS2i shift register or when the reception enable bit is changed from "0" to "1". * Parity error flag (PE) This bit is set to "1" when parity error occurs in received data. The flag is cleared at read out from PS2i shift register or when the reception enable bit is changed from "0" to "1". * Framing error / NACK reception flag (FE) At the completion of reception: The flag is set when the detection of stop bit of reception data fails. At the completion of transmission: The flag is set when NAK is received from the device side. The flag is cleared at read out from PS2i shift register, the reception enable bit or the transmission bit is changed from "0" to "1". * Transfer abort completion flag (CC) This bit is set to "1" when transfer abort procession is completed. The flag is cleared at read out from PS2i shift register, or when the reception enable bit or the transmission bit is changed from "0" to "1".
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 192 of 266
M16C/6KA Group
PS2 Interface
PS2i status register
b7 b6 b5 b4 b3 b2 b1 b0
Symbol PS20STS PS21STS PS22STS
Address 02A116 02A516 02A916
Reset Value 0016 0016 0016
Bit Symbol
TI
Bit name
Transfer completion flag
Function
0 : Waiting for transfer, During transfer 1 : Communication complete 0 : Waiting for reception, Reception complete 1 : During receiving
RW
RF
Receiving flag
CD TS PE FE CC
Reception abort incognizable flag Transfer status flag Parity error flag Framing error / NACK reception flag Transfer abort completion flag
0 : Recognizable 1 : Incognizable 0 : Transmission operation 1 : Reception operation 0 : No error 1 : Error 0 : No error 1 : Error 0 : Not abort 1 : Abort
Nothing is assigned. Meaningless in writing, "0" in reading.
Fig.GK-7 PS2i status register
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 193 of 266
M16C/6KA Group
PS2 Interface
q PS2 mode register * Sampling clock selection bits (SCK0,1) These two bits select clock frequency for sampling PS2 clock (CLK) and PS2 data (DAT). The relation between main clock (XIN) and sampling cycle is shown in table below.
XIN 8MHz 5MHz
Setting value
1/4 0.5 0.8
1/8 1.0 1.6
1/16 2.0 3.2
1/32 4.0 6.4
Sampling clock , which samples each line periodically, is used for avoiding the reflection from each line. The sampling clock will be delayed by internal circuit around 1 cycle. Thus, set the samplingclock as fast as possible. * Pin selection bit (PSEL) This bit is for selecting PS2 clock (CLK) or PS2 data (DAT) to connect to PS2Bi (i=0 to 2) .PS2Bi are external interrupt input pins. The bit setting definition is shown in table below.
Pin selection bit "0" "1"
PS2Bi (i= 0 to 2) PS2 clock (CLK) PS2 data (DAT)
* PS2 interface enable bit (PSEN) The PS2Ai (i= 0 to 2) and PS2Bi (i= 0 to 2) will be disconnected to hardware PS2 control section and become GPIO port when the bit is "0". The PS2Ai and PS2Bi will be connected to hardware PS2 control section when this bit is "1".
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 194 of 266
M16C/6KA Group
PS2 Interface
PS2 mode register
b7 b6 b5 b4 b3 b2 b1 b0
0
Symbol PS2MOD
Address 02AC16
Reset Value 0016
Bit Symbol
SCK0 SCK1 PSEL
Bit name
Sampling clock selection bits
Function
00 : Main clock /4 01 : Main clock /8 10 : Main clock /16 11 : Main clock /32
0 : PS2B connects to PS2 clock(CLK) 1 : PS2B connects to PS2 data(DAT)
RW
Pin selection bit
Nothing is assigned. Meaningless in writing, "0" in reading. PSEN0 PSEN1 PSEN2 PS2 interface enable bits 0 : P70,P73 as GPIO 1 : P70,P73 as PS2A0,PS2B0 0 : P71,P74 as GPIO 1 : P71,P74 as PS2A1,PS2B1 0 : P72,P75 as GPIO 1 : P72,P75 as PS2A2,PS2B2 Must be set to "0".
Reserved bit
Fig.GK-8 PS2 mode register
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 195 of 266
M16C/6KA Group
PS2 Interface
(2) Operation description
q Basic setting The following items should be set for PS2 mode register (address 02AC16) set when PS2 interface is used. * PS2 interface enable bit Set the PS2 interface enable bits (bit4 to 6 of PS2 mode register) to "1" to enable the PS2 channels to be used. At this time PS2 clock goes "Low" (Receiving disable). * Sampling clock selection bit Sampling clock cycle (1/4,1/8,1/16,1/32 of main clock) is selected by setting sampling clock bit (bits 0,1). * External interrupt function support pin (PS2B) selection This bit is used to select PS2 clock (CLK) or PS2 data (DAT) for the external interrupt function support pin (PS2B).
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 196 of 266
M16C/6KA Group
PS2 Interface
q Reception operation Fig.GK-9 shows the reception operation timing.
1
2
3
3
3
3
3
3
3
3
3
4
5
DAT CLK (Device side CLK) (Controller side CLK) Reception enable bit Data receiving flag Reception abort incognizable flag Transfer completion flag Interrupt request
start
D0
D1
D2
D3
D4
D5
D6
D7
parity stop
Fig.GK-9 Reception operation timing (1) Reception enable The reception operation is enabled by writing 0116 (reception enable bit = "1") to PS2i control register (address : 02A216, 02A616, 02AA16). The PS2 clock (CLK) will become "H". (2) Reception start The reception operation starts when both PS2 clock (CLK) and PS2 data (DAT) are detected with "L". (3) Data reception (The reception of data and parity bits) The content PS2 data (DAT) is read into PS2i shift register (address : 02A016, 02A416, 02A816) sequentially by the falling edge of PS2 clock (CLK). The data transfer sequence is data bit (D0 -D7) then parity bit. (4) Reception completion (Stop bit Reception completion) By detecting the falling edge of PS2 clock (CLK), the transfer completion flag (bit 0 of PS2i status register) is set to "1" after the update of error flag (bit 4 - 6 of PS2i status register) and the reception enable bit (bit 0 of PS2i control register) is cleared to "0". The PS2 clock (CLK) becomes "L" (reception disable status) and interrupt request occurs. (5) Data read out Read out data from PS2i shift register (address : 02A016,02A416,02A816). At this time , the error flags (Bit4 to 6) of and transfer completion flag (bit 0) of PS2i status register (address: 02A116, 02A516, 02A916) will be cleared to "0".
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 197 of 266
M16C/6KA Group
PS2 Interface
q Transmission operation Fig.GK-10 shows the transmission operation timing.
1
2
3
3
3
3
3
3
3
3
3
3
4
5
6
DAT (Device side DAT) (Controller side DAT) CLK (Device side CLK) (Controller side CLK) Transmission enable flag Transfer completion flag Interrupt request
start
D0
D1
D2
D3
D4
D5
D6
D7
parity stop
ack
start
D0
D1
D2
D3
D4
D5
D6
D7
parity stop
Fig.GK-10 Transmission operation timing (1) Data writing Write transmission data to PS2i shift register (address : 02A016, 02A416, 02A816). At this time,PS2 data will become "L" (transmission start). (2) Transmission enable Set 0216 (Transmission enable bit = "1") to PS2i control register (address : 02A216, 02A616, 02AA16) for enabling transmission operation. At this time , PS2 clock (CLK) will become "H". (3) Data transmission (The transmission of data, parity and stop bits) The content of PS2i shift register (address : 02A016, 02A416, 02A816) will be output to the PS2 data (DAT) sequentially by the falling edge of PS2 clock (CLK). The sequence of data transfer is data bits (D0 to D7) , Parity bit, and stop bit. (4) Acknowledge reception The content of acknowledge bit will be read by the falling edge of PS2 clock (CLK). (5) Communication completion The communication operation is completed by detecting "H" on both PS2 clock (CLK) and PS2 data (DAT). After the update of error flag (bit 4 - 6 of PS2i status register), the transfer completion flag (bit 0 of PS2i status register) is set to "1" and the reception enable bit (bit 0 of PS2i control register) is cleared to "0". At this time, PS2 clock (CLK) becomes "L" (reception disable status) and the interrupt request occurs. (6) Status clear Read out the data from PS2i shift register (address : 02A016, 02A416, 02A816). At this time , the error flags (bits 4 to 6) and transfer completion flag (Bit0) of PS2i status register (address : 02A116, 02A516, 02A916) will be cleared to "0".
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z page 198 of 266
M16C/6KA Group
PS2 Interface
q Transfer abort operation Fig.GK-11 shows the transfer abort operation timing.
1
2
3
3
3
3
45
6
DAT CLK (Device side CLK) (Controller side CLK) Transfer abort request bit Reception abort incognizable flag Transfer abort completion flag Transfer completion flag Interrupt request
start
D0
D1
D2
D3
D4
Fig.GK-11 Transfer abort operation timing ( reception)
(1) - (3) Data reception operation (4) Transfer abort request Set 0416 (transfer abort request bit = "1") to PS2i control register (address : 02A216, 02A616,02AA16). (5) Transfer abort completion The transfer abort completion flag (bit 6) and transfer completion flag (bit 0) of PS2i status register (address : 02A116, 02A516, 02A916) are set to "1", transfer abort request bit (bit 2) of PS2i control register (address : 02A216, 02A616, 02AA16) is cleared to "0". At this time, PS2 clock (CLK) becomes "L" (reception disable status) and interrupt request occurs. (6) Status clear By a pseudo read of PS2i shift register (address : 02A016, 02A416, 02A816), the transfer abort completion flag (bit 6) and transfer completion flag (bit 0) of PS2i status register (address : 02A116, 02A516, 02A916) are cleared to "0". Note: Do not execute the following transmission/reception during the period between the "L" output from PS2 clock (CLK) and the transfer abort request recognition of the device.
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 199 of 266
M16C/6KA Group
Port
Programmable I/O Ports
There are 129 programmable I/O ports: P0 to P16 (excluding P85). Each port can be set independently for input or output using the direction register. Pull-up resistances can be set in 4-port unit. (except for P10 and P14). The N channel open drain ports P60 to P63, P70 to P77, P80 to P84, P130 to P137 and P85 (input only port) do not build internal pull-up resistance. Fig.UA-1 to UA-6 show the configurations of programmable I/O ports. Each pin functions as a programmable I/O port and as the I/O for the built-in peripheral devices. To use the pins as the inputs for the built-in peripheral devices, set the direction register of each pin to input mode. When the pins are used as the outputs for the built-in peripheral devices, they function as outputs regardless of the contents of the direction registers. See the descriptions of the respective functions for how to set up the built-in peripheral devices.
(1) Direction registers
Fig.UA-7 shows the configurations of direction registers. These registers are used to choose the direction of the programmable I/O ports. Each bit in these registers corresponds one for one to each I/O pin. Note: There is no direction register bit for P85.
(2) Port registers
Fig.UA-8 shows the configurations of port registers. These registers are used to write and read data for input and output to and from exterior. A port register consists of a port latch to hold output data and a circuit to read the status of a pin. Each bit in port registers corresponds one for one to each I/O pin.
(3) Pull-up control registers
Fig.UA-9 and UA-10, UA-11 shows the configurations of pull-up control registers. The pull-up control register can be set to apply a pull-up resistance to each block of 4 ports (except for P10 and P14). When ports are set to have a pull-up resistance, the pull-up resistance is connected only when the direction register is set for input. Pull-up resistance can be set to each pin of P10 and P14.
(4) Port control register
Fig.UA-12 shows the configurations of port control register 0, 1. Fig.UA-13 shows the configurations of port control register 2, 3. The bit 0 of port control register 0 is used to read port P1 as follows: 0 : When port P1 is input port, port input level is read. When port P1 is output port , the contents of port P1 register is read. 1 : The contents of port P1 register is read always. (neither input port nor output port)
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 200 of 266
M16C/6KA Group
Port
The P0, P1, P40 to P46, P11 and P14 output type, CMOS or N channel open drain, are set by bit 0 to 6 of port control register 1 and bit 0 to 2 of port control register 3. 0 : CMOS output 1 : N channel open drain output Exception: P42 output type is N channel open drain if either bit 4 of port control register 1 or bit 2 of port control register 3 is set to "1". Bit 7 of port control register1 functions as below 0 : P40/P43 output is cleared by software only 1 : P40/P43 output is cleared by software or when output buffer 0 is read by host side. The driving ability of N channel output transistors for P140 to P143 can be selected by bit 6 of port control register 2 controls as below: 0 : Driving ability of N channel open drain output transistor is LOW 1 : Driving ability of N channel open drain output transistor is HIGH
(5) Port P4/P7 input register
Fig.UA-14 shows the configurations of P4 and P7 input register. By reading the registers, the input level of the corresponding pins can be known regardless the input/output mode. These two registers can be read regardless port direction setting. And the ports level will be read out. Port4 : Bit 0 to bit6's level will be read out. And bit7 is always "0". Port7 : Bit 0 to bit5's level will be read out. And bit6,7 is always "0".
(6) Port function selection register 0,1,2
Fig.UA-15, UA-16 shows the configurations of port function selection register 0,1. The port functions of ________ __________ UART1 input/output, TimerA0 to TimerA2 output, TimerB3,B4 input, external interrupt INT6 to INT12 input or I2C1,2 input/output can be switched by setting these two registers. By setting bit0,1 of port function selection register 2, the same frequency clock with f(XIN) can be output from P110 and P111.
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 201 of 266
M16C/6KA Group
Port
Pull-up selection
P00 to P07 P110 to P117
Direction register
Output formality selection bit Data bus Port latch (Note)
Pull-up selection
P12, P16 P140 to P147
Direction register
Output formality selection bit Data bus Port latch (Note)
Input respective peripheral function
Pull-up selection
P13, P43 to P46
Direction register "1"
Output formality selection bit Data bus Port latch
Output (Note)
Pull-up selection
P10, P11, P14, P15, P17 P40 to P42
Direction register "1"
Output formality selection bit Data bus Port latch
Output (Note)
Input respective peripheral function
(Note)
symbolizes a parasitic diode. Do not apply a voltage higher than Vcc each port.
Fig.UA-1 Programmable I/O ports (1)
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 202 of 266
M16C/6KA Group
Port
Pull-up selection
P126, P127 P153 to P157
Direction register
Data bus
Port latch (Note)
Pull-up selection
P21, P24 to P27, P50 to P57 P91, P97 P120 to P125 P160, P161
Data bus
Direction register
Port latch (Note)
Input to respective peripheral function
Pull-up selection
P47
Direction register "1"
Output Data bus Port latch (Note)
Pull-up selection
P20, P22, P23, P30 to P37 P150 to P152, P64 to P67, P90, P92
Direction register "1"
Output Data bus Port latch (Note)
Input to respective peripheral function
Note.
symbolizes a parasitic diode. Do not apply a voltage higher than Vcc to each port.
Fig.UA-2 Programmable I/O ports (2)
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z page 203 of 266
M16C/6KA Group
Port
P130 to P137
Direction register
Data bus
Port latch
(Note)
P76 to P77, P80 to P84
Direction register
Data bus
Port latch
(Note)
Input to respective peripheral function
P60 to P63, P70 to P75
Direction register "1"
Output Data bus Port latch
(Note)
Input to respective peripheral function
Note.
symbolizes a parasitic diode.
Fig.UA-3 Programmable I/O ports (3)
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 204 of 266
M16C/6KA Group
Port
Pull-up selection
Direction register
P100, P101 (Excepting the short dashes line section) P102 to P107 (Including the short dashes line section)
Data bus
Port latch (Note)
Analog input Input to respective peripheral function
P102 to P107 only
Pull-up selection
P93, P94
Direction register "1"
Output Data bus Port latch (Note)
Input to respective peripheral function
Pull-up selection
P95
Direction register "1"
Output Data bus Port latch (Note)
Input to respective peripheral function Analog input
Pull-up selection
P96
Direction register "1"
Output Data bus Port latch (Note)
Analog input
Note
symbolizes a parasitic diode. Do not apply a voltage higher than Vcc to each port.
Fig.UA-4 Programmable I/O ports (4)
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z page 205 of 266
M16C/6KA Group
Port
Pull-up selection
P87
Direction register
Data bus
Port latch (Note)
Input to respective peripheral function
Pull-up selection
Direction register
P86
"1"
Output Data bus Port latch (Note)
Note
symbolizes a parasitic diode. Do not apply a voltage higher than Vcc to each port.
Fig.UA-5 Programmable I/O ports (5)
M1 M1 signal input (Note1)
M0 M0 signal input (Note1)
RESET RESET signal input (Note1)
Note1.
symbolizes a parasitic diode. Do not apply a voltage higher than Vcc to each pin.
Fig.UA-6 I/O pins
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 206 of 266
M16C/6KA Group
Port
Port Pi direction register
b7 b6 b5 b4 b3 b2 b1 b0
Symbol PDi(i=0-15, except 8)
Address 03E216,03E316,03E616,03E716,03EA16 03EB16,03EE16,03EF16,03F316,03F616 02E216,02E316,02E616,02E716,02EA16
When reset 0016
Bit symbol
PDi_0 PDi_1 PDi_2 PDi_3 PDi_4 PDi_5 PDi_6 PDi_7
Bit name
Port Pi0 direction register Port Pi1 direction register Port Pi2 direction register Port Pi3 direction register Port Pi4 direction register Port Pi5 direction register Port Pi6 direction register Port Pi7 direction register
Function
0 : Input mode (Function as an input port) 1 : Output mode (Function as an output port) (i=0-15, except 8)
RW
Port P8 direction register
b7 b6 b5 b4 b3 b2 b1 b0
Symbol PD8
Address 03F216
When reset 00X000002
Bit symbol
PD8_0 PD8_1 PD8_2 PD8_3 PD8_4
Bit name
Port P80 direction register Port P81 direction register Port P82 direction register Port P83 direction register Port P84 direction register
Function
0 : Input mode (Function as an input port) 1 : Output mode (Function as an output port)
RW
Nothing is assigned. In an attempt to write to this bit, write "0". The value, if read, turns out to be indeterminate. PD8_6 PD8_7 Port P86 direction register Port P87 direction register 0 : Input mode (Function as an input port) 1 : Output mode (Function as an output port)
Port P16 direction register
b7 b6 b5 b4 b3 b2 b1 b0
Symbol PD16
Address 02EB16
When reset XXXXXX002
Bit symbol
PD16_0
Bit name
Port P160 direction register
Function
0 : Input mode (Function as an input port) 1 : Output mode (Function as an output port)
RW
PD16_1
Port P161 direction register
Nothing is assigned. In an attempt to write to this bit, write "0". The value, if read, turns out to be indeterminate.
Fig.UA-7 Direction register
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z page 207 of 266
M16C/6KA Group
Port
Port Pi register
b7 b6 b5 b4 b3 b2 b1 b0
Symbol Pi(i=0 to15, except 8)
Address 03E016,03E116,03E416,03E516,03E816 03E916,03EC16,03ED16,03F116,03F416 02E016,02E116,02E416,02E516,02E816
When reset Indeterminate
Bit symbol
Pi_0 Pi_1 Pi_2 Pi_3 Pi_4 Pi_5 Pi_6 Pi_7
Bit name
Port Pi0 register Port Pi1 register Port Pi2 register Port Pi3 register Port Pi4 register Port Pi5 register Port Pi6 register Port Pi7 register
Function
Data is input and output to and from each pin by reading and writing to and from each corresponding bit 0 : "L" level data 1 : "H" level data (i=0-15, except 8)
RW
Port P8 register
b7 b6 b5 b4 b3 b2 b1 b0
Symbol P8
Address 03F016
When reset Indeterminate
Bit symbol
P8_0 P8_1 P8_2 P8_3 P8_4 P8_5 P8_6 P8_7
Bit name
Port P80 register Port P81 register Port P82 register Port P83 register Port P84 register Port P85 register Port P86 register Port P87 register
Function
Data is input and output to and from each pin by reading and writing to and from each corresponding bit (except for P85) 0 : "L" level data 1 : "H" level data
RW
Port P16 register
b7 b6 b5 b4 b3 b2 b1 b0
Symbol P16
Address 02E916
When reset Indeterminate
Bit symbol
PD16_0
Bit name
Port P160 register
Function
Data is input and output to and from each pin by reading and writing to and from each corresponding bit 0 : "L" level data 1 : "H" level data
RW
PD16_1
Port P161 register
Nothing is assigned. In an attempt to write to this bit, write "0". The value, if read, turns out to be indeterminate.
Fig.UA-8 Port register
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z page 208 of 266
M16C/6KA Group
Port
Pull-up control register 0
b7 b6 b5 b4 b3 b2 b1 b0
Symbol PUR0
Address 03FC16
When reset 0016
Bit symbol
PU00 PU01 PU02 PU03 PU04 PU05 PU06 PU07
Bit name
P00 to P03 pull-up P04 to P07 pull-up P10 to P13 pull-up P14 to P17 pull-up P20 to P23 pull-up P24 to P27 pull-up P30 to P33 pull-up P34 to P37 pull-up
Function
The corresponding port is pulled high with a pull-up resistor 0: Not pulled high 1: Pulled high
RW
Pull-up control register 1
b7 b6 b5 b4 b3 b2 b1 b0
Symbol PUR1
Address 03FD16
When reset 0016
Bit symbol
PU10 PU11 PU12 PU13
Bit name
P40 to P43 pull-up P44 to P47 pull-up P50 to P53 pull-up P54 to P57 pull-up
Function
The corresponding port is pulled high with a pull-up resistor 0: Not pulled high 1: Pulled high
RW
Nothing is assigned. (Note) Can't write to this bit. The value, if read, turns out to be "0". PU15 P64 to P67 pull-up
Nothing is assigned. (Note) Can't write to this bit. The value, if read, turns out to be "0". Note.Since P60 to P63 and P70 to P77 are N-channel open drain ports, internal pull-up is not available for them.
Pull-up control register 2
b7 b6 b5 b4 b3 b2 b1 b0
Symbol PUR2
Address 03FE16
When reset 0016
Bit symbol
Bit name
Function
RW
Nothing is assigned. (Note) Can't write to this bit. The value, if read, turns out to be "0". PU21 PU22 PU23 P86, P87 pull-up(Note) P90 to P93 pull-up P94 to P97 pull-up The corresponding port is pulled high with a pull-up resistor 0: Not pulled high 1: Pulled high
Nothing is assigned. Can't write to this bit. The value, if read, turns out to be "0". Note.Since P80 to P84 are N-channel open drain ports, internal pull-up is not available for them. And P85 is input port only , also no internal pull-up is available.
Fig.UA-9 Pull-up control register(1)
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z page 209 of 266
M16C/6KA Group
Port
Pull-up control register 3
b7 b6 b5 b4 b3 b2 b1 b0
Symbol PUR3
Address 02FC16
When reset 0016
Bit symbol
PU30 PU31 PU32 PU33
Bit name
P110 to P113 pull-up P114 to P117 pull-up P120 to P123 pull-up P124 to P127 pull-up
Function
The corresponding port is pulled high with a pull-up resistor 0 : Not pulled high 1 : Pulled high
RW
Nothing is assigned. Can't write to this bit. The value, if read, turns out to be "0".
Pull-up control register 4
b7 b6 b5 b4 b3 b2 b1 b0
Symbol PUR4
Address 02FD16
When reset 0016
Bit symbol
PU40 PU41 PU42
Bit name
P150 to P153 pull-up P154 to P157 pull-up P160, P161 pull-up
Function
The corresponding port is pulled high with a pull-up resistor 0 : Not pulled high 1 : Pulled high
RW
Nothing is assigned. Can't write to this bit. The value, if read, turns out to be "0".
Fig.UA-10 Pull-up control register(2)
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 210 of 266
M16C/6KA Group
Port
Pull-up control register 5
b7 b6 b5 b4 b3 b2 b1 b0
Symbol PUR5
Address 02F216
When reset 0016
Bit symbol
PU50 PU51 PU52 PU53 PU54 PU55 PU56 PU57
Bit name
P100 pull-up P101 pull-up P102 pull-up P103 pull-up P104 pull-up P105 pull-up P106 pull-up P107 pull-up
Function
The corresponding port is pulled high with a pull-up resistor 0 : Not pulled high 1 : Pulled high
RW
Pull-up control register 6
b7 b6 b5 b4 b3 b2 b1 b0
Symbol PUR6
Address 02F316
When reset 0016
Bit symbol
PU60 PU61 PU62 PU63 PU64 PU65 PU66 PU67
Bit name
P140 pull-up P141 pull-up P142 pull-up P143 pull-up P144 pull-up P145 pull-up P146 pull-up P147 pull-up
Function
The corresponding port is pulled high with a pull-up resistor 0 : Not pulled high 1 : Pulled high
RW
Fig.UA-11 Pull-up control register(3)
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 211 of 266
M16C/6KA Group
Port
Port control register 0
b7 b6 b5 b4 b3 b2 b1 b0
Symbol PCR0
Address 03FF16
When reset 0016
Bit Symbol
PCR00
Bit name
Port P1 control register
Function
0 : When input port, read port input level. When output port, read the contents of port P1 register 1 : Read the contents of port P1 register though input/output port.
RW
Nothing is assigned. Can't write to this bit. The value, if read, turns out to be "0".
Port control register 1
b7 b6 b5 b4 b3 b2 b1 b0
Symbol PCR1
Address 02FE16
When reset 0016
Bit Symbol
PCR10 PCR11 PCR12 PCR13 PCR14 PCR15 PCR16 PCR17
Bit name
Output type selection bit (P00 to P03) Output type selection bit (P04 to P07) Output type selection bit (P10 to P13) Output type selection bit (P14 to P17) Output type selection bit (P40 to P46) Output type selection bit (P110 to P113) Output type selection bit (P114 to P117) P40,P43 output clear function selection bit
Function
0 : CMOS 1 : N-channel open drain 0 : CMOS 1 : N-channel open drain 0 : CMOS 1 : N-channel open drain 0 : CMOS 1 : N-channel open drain 0 : CMOS 1 : N-channel open drain 0 : CMOS 1 : N-channel open drain 0 : CMOS 1 : N-channel open drain 0 : Cleared by software only 1 : Cleared by software or when output buffer is read by host side.
RW
Fig.UA-12 Port control register 0, 1
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 212 of 266
M16C/6KA Group
Port
Port control register 2
b7 b6 b5 b4 b3 b2 b1 b0
000000
Symbol PCR2
Address 02FF16
When reset 0016
Bit symbol
Reserved bit Reserved bit Reserved bit Reserved bit Reserved bit Reserved bit PCR26
Bit name
Function
Must be set to "0" Must be set to "0" Must be set to "0" Must be set to "0" Must be set to "0" Must be set to "0"
RW
Drive polarity selection bit (P140 to P143)
0 : Low side 1 : High side
Nothing is assigned. Can't write to this bit. The value, if read, turns out to be "0".
Port control register 3
b7 b6 b5 b4 b3 b2 b1 b0
Symbol PCR3
Address 02F716
When reset 0016
Bit symbol
PCR30 PCR31 PCR32
Bit name
Output type selection bit (P140 to P143) Output type selection bit (P144 to P147) Output type selection bit (P42)
Function
0 : CMOS 1 : N-channel open drain 0 : CMOS 1 : N-channel open drain 0 : CMOS 1 : N-channel open drain
RW
Nothing is assigned. Can't write to this bit. The value, if read, turns out to be "0".
Fig.UA-13 Port control register 2, 3
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 213 of 266
M16C/6KA Group
Port
Port P4 input register
b7 b6 b5 b4 b3 b2 b1 b0
Symbol P4PIN
Address 02FA16
When reset 0XXXXXXX2
Bit Symbol
P4PIN_0 P4PIN_1 P4PIN_2 P4PIN_3 P4PIN_4 P4PIN_5 P4PIN_6
Bit name
Port P40 input register Port P41 input register Port P42 input register Port P43 input register Port P44 input register Port P45 input register Port P46 input register
Function
For reading P40 pin level For reading P41 pin level For reading P42 pin level For reading P43 pin level For reading P44 pin level For reading P45 pin level For reading P46 pin level
RW
Nothing is assigned. Can't write to this bit. The value, if read, turns out to be "0".
Port P7 input register
b7 b6 b5 b4 b3 b2 b1 b0
Symbol P7PIN
Address 02FB16
When reset 00XXXXXX2
Bit Symbol
P7PIN_0 P7PIN_1 P7PIN_2 P7PIN_3 P7PIN_4 P7PIN_5
Bit name
Port P70 input register Port P71 input register Port P72 input register Port P73 input register Port P74 input register Port P75 input register
Function
For reading P70 pin level For reading P71 pin level For reading P72 pin level For reading P73 pin level For reading P74 pin level For reading P75 pin level
RW
Nothing is assigned. Can't write to this bit. The value, if read, turns out to be "0".
Fig.UA-14 Port P4,P7 input register
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 214 of 266
M16C/6KA Group
Port
Port function selection register 0
b7 b6 b5 b4 b3 b2 b1 b0
0
0
0
Symbol PSL0
Address 02F816
When reset 0016
Bit Symbol
Reserved bit PSL01
Bit name
Function
Must be set to "0" .
RW
UART1 I/O pin selection bit
0 : P64 to P67 1 : P14 to P17 Must be set to "0" . 0 : P103 1 : P14 0 : P104 1 : P15 0 : P105 1 : P16 0 : P106 1 : P17 Must be set to "0" .
Reserved bit
PSL03
INT7 input pin selection bit
PSL04
INT8 I/O pin selection bit
PSL05 PSL06
INT9 I/O pin selection bit INT10 I/O pin selection bit
Reserved bit
Port function selection register 1
b7 b6 b5 b4 b3 b2 b1 b0
Symbol PSL1
Address 02F916
When reset 0016
Bit Symbol
PSL10
Bit name
TA0 output pin selection bit 0 : P40 1 : P150 0 : P41 1 : P151 0 : P42 1 : P152 0 : P93 1 : P160 0 : P94 1 : P161
Function
RW
PSL11
TA1 output pin selection bit
PSL12
TA2 output pin selection bit
PSL13
TB3 output pin selection bit
PSL14
TB4 output pin selection bit
PSL15 (Note)
INT6-INT11 input pin switching bit
0 : P97, P103 to P107 1 : P120, P121 to P125
Nothing is assigned. Meaningless in writing, "0" in reading. Note. If this is set to "1" then port function selection register 0 (address 02F816) bit 3 to bit6 setting will be ignored.
Fig.UA-15 Port function selection register 0,1
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z page 215 of 266
M16C/6KA Group
Port
Port function selection register 2
b7 b6 b5 b4 b3 b2 b1 b0
Symbol PSL2
Address 02F116
When reset 0016
Bit Symbol
PSL20
Bit name
Function
RW
P110 : f1 output function selection bit 0 : P110 as GPIO 1 : P110 as f1 output P111 : f1 output function selection bit 0 : P111 as GPIO 1 : P111 as f1 output S I/O3 I/O pin selection bit 0 : P90 to P92 1 : P150 to P152 0 : P95 to P97 1 : P155 to P157 0 : P62, P63 1 : P81, P82 0 : P76, P77 1 : P83, P84
PSL21
PSL22
PSL23
S I/O4 I/O pin selection bit I2C1 I/O pin selection bit (Note 1) I2C2 I/O pin selection bit (Note 1)
PSL24
PSL25
Nothing is assigned. Meaningless in writing, "0" in reading. Note 1 When their pins will be changed, I2C1 or I2C2 is not active. And after their pins were changed, the corresponding interrupt request bit should be cleared to "0".
Fig.UA-16 Port function selection register 2
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 216 of 266
M16C/6KA Group
Port
Table.UA-1 Example connection of unused pins in single-chip mode
Pin name Ports P0 to P10 (excluding P85) Ports P11 to P16 XOUT (Note) NMI AVCC AVSS, VREF, M1 Connection After setting for input mode, connect every pin to VSS or VCC via a resistor; or after setting for output mode, leave these pins open. After setting for input mode, connect every pin to VSS or VCC via a resistor; or after setting for output mode, leave these pins open. Open Connect via resistor to VCC (pull-up) Connect to VCC Connect to VSS
Note: With external clock input to XIN pin.
Microcomputer Port P0 to P16 (input mode) (except for P85)
(input mode) (output mode)
open
NMI XOUT open VCC AVCC 0.47 F M1 AVSS VREF M0 VSS In single-chip mode
Fig.UA-17 Example connection of unused pins
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 217 of 266
M16C/6KA Group
Usage precaution
Usage Precaution Timer A (timer mode)
(1) Reading the timer Ai register while a count is in progress allows reading, with arbitrary timing, the value of the counter. But, reading the timer Ai register with the reload timing gets "FFFF16". Reading the timer Ai register after setting a value in the timer Ai register with a count halted but before the counter starts counting gets a setting value to the timer.
Timer A (event counter mode)
(1) Reading the timer Ai register while a count is in progress allows reading, with arbitrary timing, the value of the counter. But, reading the timer Ai register with the reload timing gets "FFFF16" by underflow or "000016" by overflow. Reading the timer Ai register after setting a value in the timer Ai register with a count halted but before the counter starts counting gets a setting value to the timer. (2) When stop counting in free run type, set timer again.
Timer A (one-shot timer mode)
(1) Setting the count start flag to "0" while a count is in progress causes as follows: * The counter stops counting and a content of reload register is reloaded. * The TAiOUT pin outputs "L" level. * The interrupt request generated and the timer Ai interrupt request bit goes to "1". (2) The timer Ai interrupt request bit goes to "1" if the timer's operation mode is set using any of the following procedures: * Selecting one-shot timer mode after reset. * Changing operation mode from timer mode to one-shot timer mode. * Changing operation mode from event counter mode to one-shot timer mode. Therefore, to use timer Ai interrupt (interrupt request bit), set timer Ai interrupt request bit to "0" after the above listed changes have been made.
Timer A (pulse width modulation mode)
(1) The timer Ai interrupt request bit becomes "1" if setting operation mode of the timer in compliance with any of the following procedures: * Selecting PWM mode after reset. * Changing operation mode from timer mode to PWM mode. * Changing operation mode from event counter mode to PWM mode. Therefore, to use timer Ai interrupt (interrupt request bit), set timer Ai interrupt request bit to "0" after the above listed changes have been made. (2) Setting the count start flag to "0" while PWM pulses are being output causes the counter to stop counting. If the TAiOUT pin is outputting an "H" level in this instance, the output level goes to "L", and the timer Ai interrupt request bit goes to "1". If the TAiOUT pin is outputting an "L" level in this instance, the level does not change, and the timer Ai interrupt request bit does not becomes "1".
Timer B (timer mode, event counter mode)
(1) Reading the timer Bi register while a count is in progress allows reading , with arbitrary timing, the value of the counter. But, reading the timer Bi register with the reload timing gets "FFFF16". Reading the timer Bi register after setting a value in the timer Bi register with a count halted but before the counter starts counting gets a setting value to the timer.
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 218 of 266
M16C/6KA Group
Usage precaution
Timer B (pulse period/pulse width measurement mode)
(1) If changing the measurement mode select bit is set after a count is started, the timer Bi interrupt request bit goes to "1". (2) When the first effective edge is input after a count is started, an indeterminate value is transferred to the reload register. At this time, timer Bi interrupt request is not generated.
A-D Converter
(1) Write to each bit (except bit 6) of A-D control register 0, to each bit of A-D control register 1, and to bit 0 of A-D control register 2 when A-D conversion is stopped (before a trigger occurs). In particular, when the Vref connection bit is changed from "0" to "1", start A-D conversion after an elapse of 1 s or longer. (2) When changing A-D operation mode, select analog input pin again. (3) Using one-shot mode or single sweep mode Read the correspondence A-D register after confirming A-D conversion is finished. (It is known by A-D conversion interrupt request bit.) (4) Using repeat mode, repeat sweep mode 0 or repeat sweep mode 1 Use the undivided main clock as the internal CPU clock.
Stop Mode and Wait Mode
____________
(1) When returning from stop mode by hardware reset, RESET pin must be set to "L" level until main clock oscillation is stabilized. (2) When switching to either wait mode or stop mode, instructions occupying four bytes either from the WAIT instruction or from the instruction that sets the every-clock stop bit to "1" within the instruction queue are prefetched and then the program stops. So put at least four NOPs in succession either to the WAIT instruction or to the instruction that sets the every-clock stop bit to "1".
Interrupts
(1) Reading address 0000016 * When maskable interrupt is occurred, CPU read the interrupt information (the interrupt number and interrupt request level) in the interrupt sequence. The interrupt request bit of the certain interrupt written in address 0000016 will then be set to "0". Reading address 0000016 by software sets enabled highest priority interrupt source request bit to "0". Though the interrupt is generated, the interrupt routine may not be executed. Do not read address 0000016 by software. (2) Setting the stack pointer * The value of the stack pointer immediately after reset is initialized to 000016. Accepting an interrupt before setting a value in the stack pointer may become a factor of runaway. Be sure to set a value in the stack pointer before accepting an interrupt. _______ When using the NMI interrupt, initialize the stack point at the beginning of a program. Concerning the first _______ instruction immediately after reset, generating any interrupts including the NMI interrupt is prohibited. _______ (3) The NMI interrupt _______ * As for the NMI interrupt pin, an interrupt cannot be disabled. Connect it to the VCC pin via a resistor (pull-up) if unused. Be sure to work on it. _______ * Do not get into stop mode with the NMI pin set to "L".
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z page 219 of 266
M16C/6KA Group
Usage precaution
(4) External interrupt _______ _________ * When the polarity of the INT0 to INT11 pins is changed, the interrupt request bit is sometimes set to "1". After changing the polarity, set the interrupt request bit to "0". (5) Rewrite the interrupt control register * To rewrite the interrupt control register, do so at a point that does not generate the interrupt request for that register. If there is possibility of the interrupt request occur, rewrite the interrupt control register after the interrupt is disabled. The program examples are described as follow:
Example 1:
INT_SWITCH1: FCLR I AND.B #00h, 0055h NOP NOP FSET I ; Disable interrupts. ; Clear TA0IC int. priority level and int. request bit. ; Four NOP instructions are required when using HOLD function. ; Enable interrupts.
Example 2:
INT_SWITCH2: FCLR I AND.B #00h, 0055h MOV.W MEM, R0 FSET I ; Disable interrupts. ; Clear TA0IC int. priority level and int. request bit. ; Dummy read. ; Enable interrupts.
Example 3:
INT_SWITCH3: PUSHC FLG FCLR I AND.B #00h, 0055h POPC FLG ; Push Flag register onto stack ; Disable interrupts. ; Clear TA0IC int. priority level and int. request bit. ; Enable interrupts.
The reason why two NOP instructions (four when using the HOLD function) or dummy read are inserted before FSET I in Examples 1 and 2 is to prevent the interrupt enable flag I from being set before the interrupt control register is rewritten due to effects of the instruction queue.
* When a instruction to rewrite the interrupt control register is executed but the interrupt is disabled, the interrupt request bit is not set sometimes even if the interrupt request for that register has been generated. This will depend on the instruction. If this creates problems, use the below instructions to change the register. Instructions : AND, OR, BCLR, BSET Noise (1) Insert the by-pass condenser to the Vcc-Vss line for preventing a noise and latch-up. Connect the by -pass condencer (about 0.1F) between Vcc pin and Vss pin. It is distance must be shortest rather sicker line.
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 220 of 266
M16C/6KA Group
Electrical characteristics
Table.ZA-1 Absolute maximum ratings
Symbol Vcc AVcc Supply voltage Analog Supply voltage Input voltage VI RESET,M0,M1,VREF,XIN, P00 to P07,P10 to P17,P20 to P27,P30 to P37, P40 to P47,P50 to P57,P64 to P67,P86,P87, P90 to P97,P100 to P107,P110 to P117, P120 to P127,P140 to P147,P150 to P157, P160,P161 P60 to P63,P70 to P77,P80 to P84,P85, P130 to P137 output voltage VO P00 to P07,P10 to P17,P20 to P27,P30 to P37, P40 to P47,P50 to P57,P64 to P67,P86,P87, P90 to P97,P100 to P107,P110 to P117, P120 to P127,P140 to P147,P150 to P157, P160,P161,XOUT P60 to P63,P70 to P77,P80 to P84, P130 to P137 Pd Topr Tstg Power dissipation Operating ambient temperature Storage temperature Ta=25 C Parameter Condition VCC=AVCC VCC=AVCC Rated value -0.3 to 4.6 -0.3 to 4.6 Unit V V
-0.3 to Vcc+0.3
V
-0.3 to 5.8
V
-0.3 to Vcc+0.3
V
-0.3 to 5.8 300 -20 to 85 -40 to 125
V mW C C
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 221 of 266
M16C/6KA Group
Electrical characteristics
Table.ZA-2 Recommended operating conditions (referenced to Vcc=3.0V to 3.6V,Ta= -20 to 85oC)
Symbol Vcc AVcc Vss AVss Supply voltage Analog Supply voltage Supply voltage Analog Supply voltage "H" input voltage Parameter Min. 3.0 Standard Typ. 3.3 Vcc 0 0 P00 to P07, P10 to P17,P20 to P27, P30 to P37,P40 to P47, P50 to P57, P64 to P67,P86,P87,P90 to P97, P100 to P107, P110 to P117, P120 to P127,P140 to P147, P150 to P157, P160,P161,XIN, RESET, M0,M1 P60 to P63, P70 to P77,P80 to P84,P85,P130 to P137, PSA0 to PSA2, PSB0 to PSB2 LAD0 to LAD3,LFRAME,LCLK,SERIRQ,CLKRUN SDA0,SCL0,SDA1,SCL1,SDA2,SCL2, P60 to P63,P76,P77,P81 to P84 "L" input voltage VIL
I2C-BUS input level selected SMBUS input level selected
Unit Max. 3.6 V V V V Vcc V
VIH
0.8Vcc
0.8Vcc 0.6Vcc 0.7Vcc 1.4 0
5.5 Vcc 5.5 5.5 0.2Vcc
V V V V V
P00 to P07, P10 to P17,P20 to P27, P30 to P37,P40 to P47, P50 to P57, P64 to P67,P86,P87,P90 to P97, P100 to P107, P110 to P117, P120 to P127,P140 to P147, P150 to P157, P160,P161,XIN, RESET, M0,M1 P60 to P63, P70 to P77,P80 to P84,P85,P130 to P137, PSA0 to PSA2, PSB0 to PSB2 LAD0 to LAD3,LFRAME,LCLK,SERIRQ,CLKRUN SDA0,SCL0,SDA1,SCL1,SDA2,SCL2, P60 to P63,P76,P77,P81 to P84
I2C-BUS input level selected SMBUS input level selected
0 0 0 0
0.2Vcc 0.2Vcc 0.3Vcc 0.6
V V V V
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 222 of 266
M16C/6KA Group
Electrical characteristics
Table.ZA-3 Recommended operating conditions (referenced to Vcc=3.0V to 3.6V,Ta= -20 to 85oC)
Symbol IOH (peak) "H"peak output current Parameter P00 to P07, P10 to P17,P20 to P27,P30 to P37,P40 to P47, P50 to P57,P64 to P67,P86 to P87,P90 to P97,P100 to P107, P110 to P117, P120 to P127,P140 to P147,P150 to P157, P160,P161 P00 to P07, P10 to P17,P30 to P37,P40 to P47, P50 to P57,P60 to P67,P76 to P77,P80 to P84, P86 to P87, P90 to P97,P100 to P107, P110 to P117,P120 to P127, P130 to P137,P144 to P147, P150 to P157,P160,P161 P20 to P27 IOL (peak) IOH (avg) "L"peak output current P140 to P143 Driven ability : High Driven ability : Low Min. Standard Typ. Max. -10.0 Unit
mA
IOL (peak)
"L"peak output current
10.0 20.0 20.0 10.0 -5.0
mA mA mA mA mA
"H" average output P00 to P07, P10 to P17,P20 to P27,P30 to P37, P40 to P47,P50 to P57,P60 to P67,P86 to P87,P90 to P97, current P100 to P107, P110 to P117, P120 to P127,P140 to P147, P150 to P157,P160,P161 "L"average output P00 to P07, P10 to P17,P30 to P37, P40 to P47, P50 to P57,P60 to P67,P76 to P77,P80 to P84, P86 to P87, current P90 to P97,P100 to P107,P110 to P117,P120 to P127, P130 to P137,P140 to P147,P150 to P157,P160,P161 P20 to P27 "L"average output P140 to P143 current
Main clock input oscillation frequency
IOL (avg)
5.0
mA
15.0 Driven ability : High Driven ability : Low 0 15.0 5.0 8
IOL (avg) f (XIN)
mA mA mA MHz
Note1 : The average output current is the average value during the 100ms period limited current. Note2 : The value are as follow: The sum of IOL (peak) of P0,P1,P2,P86 to P87,P9,P10,P11,P120 to P126,P153 to P157 P16 should be under 80mA. The sum of IOH (peak) of P0,P1,P2,P86 to P87,P9,P10,P11,P120 to P126,P153 to P157 P16 should be under 80mA. The sum of IOL (peak) of P3,P4,P5,P6,P7,P80 to P84,P13,P14,P150 to P152 should be under 80mA. The sum of IOH (peak) of P3,P4,P5,P64 to P67,P14,P150 to P152 should be under 80mA.
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 223 of 266
M16C/6KA Group
Electrical characteristics
Table.ZA-4 Electrical characteristics (referenced to Vcc=3.0V, Vss=0V, Ta=25oC, f(XIN)=16MHz with 0 wait unless otherwise specified)
Symbol VOH High output voltage Parameter P00 to P07, P10 to P17, P20 to P27, P30 to P37, P40 to P47, P50 to P57, P64 to P67, P86, P87, P90 to P97, P100 to P107, P110 to P117, P120 to P127, P140 to P147, P150 to P157, P160, P161 XOUT HIGH POWER LOWPOWER P00 to P07, P10 to P17, P30 to P37, P40 to P47,P50 to P57, P60 to P67, P70 to P77, P80 to P84, P86, P87, P90 to P97, P100 to P107, P110 to P117, P120 to P127, P130 to P137, P140 to P147, P150 to P157, P160, P161 P20 to P27 P140 to P143 HIGH POWER LOWPOWER XOUT HIGH POWER LOWPOWER _______ _________ TA0IN to TA4IN, TB0IN to TB5IN, INT0 to INT11, __________ ________ ADTRG, CTS1, CLK1, CLK3, CLK4, SIN3, SIN4, _______ RXD1, ICCK, NMI, KI00 to KI07 ____________ RESET P00 to P07, P10 to P17, P20 to P27, P30 to P37, P40 to P47, P50 to P57, P60 to P67, P70 to P77, P80 to P87, P90 to P97, P100 to P107, P120 to P127, P130 to P137, P140 to P147, ____________ P150 to P157, P160, P161, XIN, RESET, M0, M1 P00 to P07, P10 to P17, P20 to P27, P30 to P37, P40 to P47, P50 to P57, P60 to P67, P70 to P77, P80 to P87, P90 to P97, P100 to P107, P110 to P117, P120 to P127, P130 to P137, P140 to P147, P150 to P157, P160, P161, ____________ XIN, RESET, M0, M1 P00 to P07, P10 to P17, P20 to P27, P30 to P37, P40 to P47, P50 to P57, P64 to P67, P86, P87, P90 to P97, P100 to P107, P110 to P117, P120 to P127, P140 to P147, P150 to P157, P160, P161 XIN When reset, the output pins are opened , the other pins are connected to Vss. Measuring condition IOH=-1mA Min. 2.5 Standard Typ. Max. V Unit
VOH VOL
High output voltage Low output voltage
IOH= -0.1mA IOH= -50A
2.5 2.5
V
IOL=1mA
0.5
V
VOL VOL VT+VT-
Low output voltage Low output voltage Hysteresis
VCC=3V, IOL=3mA IOL=3mA IOL=1mA IOH=0.1mA IOH=50A 0.2 0.2
0.5 0.5 0.5 0.5 0.5 0.8 1.8
V V V
V V
VT+VTIIH
Hysteresis HIGH input current
VI=3V
4.0
A
IIL
Low input current
VI=0V
-4.0
A
R PULLUP
Pull-up resistance
VI=0V
66.0
120.0
250.0
k
R fXIN V RAM I CC
Feedback resistance RAM retention voltage Power supply current
3.0 When clock is stopped f(XIN)=16MHZ, Square wave without division Ta=25C When clock is stopped Ta=85C When clock is stopped 2.0 16.0 24.0 100.0 300.0
M V mA A A
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 224 of 266
M16C/6KA Group
Electrical characteristics
Table.ZA-5 A-D conversion characteristics (referenced to Vcc=AVcc=VREF=3V,Vss=AVss=0V at Ta=25oC unless otherwise specified)
Symbol Resolution Absolute accuracy RLADDER tCONV VREF VIA Ladder resistance Conversion time Reference voltage Analog input voltage 8 bit 10 bit 8 bit 10 bit Parameter Measuring condition VREF =VCC VREF =VCC=3V, OAD=fAD VREF =VCC 10 6.125 7.375 2.7 0 VCC VREF Min. Standard Typ. Max. 10 2 6 40 Unit Bits LSB LSB kW ms ms V V
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 225 of 266
M16C/6KA Group
Electrical characteristics
Timing requirements (referenced to Vcc=3V,Vss=0V at Ta=25oC unless otherwise specified) Table.ZA-6 External clock input
Symbol
tc tw(H) tw(L) tr tf
Parameter External clock input cycle time External clock input HIGH pulse width External clock input LOW pulse width External clock rising time External clock falling time
Standard Min.
62.5 25 25 9 9
Max.
Unit
ns ns ns ns ns
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 226 of 266
M16C/6KA Group
Electrical characteristics
Timing requirements (referenced to Vcc=3V,Vss=0V at Ta=25oC unless otherwise specified) Table.ZA-7 Timer A input (The count input of event counter mode)
Symbol tc(TA) tw(TAH) tw(TAL) TAiIN input cycle time TAiIN input "H" pulse width TAiIN input "L" pulse width Parameter Standard Min. 150 60 60 Max. Unit ns ns ns
Table.ZA-8 Timer A input (The gating input of timer mode)
Symbol tc(TA) tw(TAH) tw(TAL) TAiIN input cycle time TAiIN input "H" pulse width TAiIN input "L" pulse width Parameter Standard Min. 600 300 300 Max. Unit ns ns ns
Table.ZA-9 Timer A input (The external trigger input of one shot timer mode)
Symbol tc(TA) tw(TAH) tw(TAL) TAiIN input cycle time TAiIN input "H" pulse width TAiIN input "L" pulse width Parameter Standard Min. 300 150 150 Max. Unit ns ns ns
Table.ZA-10 Timer A input (The external trigger input of pulse width modulation mode)
Symbol tw(TAH) tw(TAL) TAiIN input "H" pulse width TAiIN input "L" pulse width Parameter Standard Min. 150 150 Max. Unit ns ns
Table.ZA-11 Timer A input (The up down input of event counter mode)
Symbol tc(UP) tw(UPH) tw(UPL) tsu(UP-TIN) th(TIN-UP) TAiOUT input cycle time TAiOUT input "H" pulse width TAiOUT input "L" pulse width TAiOUT input setup time TAiOUT input hold time Parameter Standard Min. 3000 1500 1500 200 200 Max. Unit ns ns ns ns ns
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 227 of 266
M16C/6KA Group
Electrical characteristics
Timing requirements (referenced to Vcc=3V,Vss=0V at Ta=25oC unless otherwise specified) Table.ZA-12 Timer B input (The count input of event counter mode)
Symbol tc(TB) tw(TBH) tw(TBL) tc(TB) tw(TBH) tw(TBL) Parameter TBiIN input cycle time (single edge count) TBiIN input "H" pulse width (single edge count) TBiIN input "L" pulse width (single edge count) TBiIN input cycle time (double edge count) TBiIN input "H" pulse width (double edge count) TBiIN input "L" pulse width (double edge count) Standard Min. 150 60 60 300 160 160 Max. Unit ns ns ns ns ns ns
Table.ZA-13 Timer B input (Pulse period measurement mode)
Symbol tc(TB) tw(TBH) tw(TBL) TBiIN input cycle time TBiIN input "H" pulse width TBiIN input "L" pulse width Parameter Standard Min. 600 300 300 Max. Unit ns ns ns
Table.ZA-14 Timer B input (Pulse width measurement mode)
Symbol tc(TB) tw(TBH) tw(TBL) TBiIN input cycle time TBiIN input "H" pulse width TBiIN input "L" pulse width Parameter Standard Min. 600 300 300 Max. Unit ns ns ns
Table.ZA-15 A-D trigger input
Symbol tc(AD) tw(ADL) Parameter ADTRG input cycle time (The Min. of trigger) ADTRG input "L" pulse width Standard Min. 1500 200 Max. Unit ns ns
Table.ZA-16 Serial I/O
Symbol tc(CK) tw(CKH) tw(CKL) td(C-Q) th(C-Q) tsu(D-C) th(C-D) CLKi input cycle time CLKi input "H" pulse width CLKi input "L" pulse width TxDi output delay time TxDi hold time RxDi input setup time RxDi input hold time
______
Parameter
Standard Min. 300 150 150 160 0 30 50 Max.
Unit ns ns ns ns ns ns ns
Table.ZA-17 External interrupt INTi input
Symbol tw(INH) tw(INL) INTi input "H" pulse width INTi input "L" pulse width Parameter Standard Min. 380 380 Max. Unit ns ns
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 228 of 266
M16C/6KA Group
Electrical characteristics
Timing requirements (referenced to Vcc = 3.0 to 3.6V, Vss = 0V, Ta =25 C) Table. ZA-18 Multi-master I2C-BUS line
Symbol tBUF tHD;STA tLOW tR tHD;DAT tHIGH tF tsu;DAT tsu;STA tsu;STO Bus free time The hold time in start condition The hold time in SCL clock "0" status SCL, SDA signals' rising time Data hold time The hold time in SCL clock "1" status SCL, SDA signals' falling time Data setup time The setup time in restart condition Stop condition setup time Parameter Standard clock mode Min. Max. 4.7 4.0 4.7 1000 0 4.0 300 250 4.7 4.0 High-speed clock mode Min. Max. 1.3 0.6 1.3 20+0.1Cb 0 0.6 20+0.1Cb 100 0.6 0.6 300 0.9 300 Unit s s s ns s s ns ns s s
Table. ZA-19 PS2 interface (referenced to Vcc = 3.0 to 3.6V, Vss = 0V, Ta =25 C)
Symbol twL twH tsu th td tv PS2 clock "L" pulse width PS2 clock "H" pulse width PS2 data setup time PS2 data hold time PS2 data delay time PS2 data valid time Parameter Min. 30 30 5 0 0 twL-5 twL-5 Standard Typ. Max. 50 50 Unit s s s ns s s
Table. ZA-20 LPC bus interface/serial interrupt output
Symbol tC(CLK) tWH(CLK) tWL(CLK) tsu(D-C) th(C-D) tV(C-D) toff(A-F) Parameter LCLK clock input cycle time LCLK clock input "H" pulse width LCLK clock input "L" pulse width
_______________ _______________
Standard Min. 30 11 11 7 0 2 11 28 Typ. Max.
Unit ns ns ns ns ns ns ns
LAD3-LAD0, SERIRQ, CLKRUN, LFRAME Input setup time
_______________ _______________
LAD3-LAD0, SERIRQ, CLKRUN , LFRAME input hold time
_______________ _______________
LAD3-LAD0, SERIRQ, CLKRUN , LFRAME valid delay time
_______________
LAD3-LAD0, SERIRQ, CLKRUN floating output delay time
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 229 of 266
M16C/6KA Group
Timing
P0 P1 P2 P3 P4 P5 P6 P7 P8 P9 P10 P11 P12 P13 P14 P15 P16
30pF
Fig.ZA-1 The measuring circuit for port 0 to port 16
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 230 of 266
M16C/6KA Group
Timing
tc(TA) tw(TAH) TAiIN input tw(TAL)
tc(UP) tw(UPH) TAiOUT input tw(UPL)
TAiOUT input (Up down input) In event counter mode TAiIN input (when selecting the fulling edge count) TAiIN input (when selecting the rising edge count) tc(TB) tw(TBH) TBiIN input tw(TBL) tc(AD) tw(ADL) ADTRG input th(TIN-UP) tsu(UP-TIN)
tc(CK) tw(CKH) CLKi tw(CKL) th(C-Q) TxDi td(C-Q) RxDi tw(INL) INTi input tw(INH) tsu(D-C) th(C-D)
Fig.ZA-2 Timing diagram (1)
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z page 231 of 266
M16C/6KA Group
Timing
SDA
tBUF tLOW tR tF
Sr p
tHD:STA
tsu:STO
SCL
p
S
tHD:STA
tHD:DTA
tHIGH
tsu:DAT
tsu:STA
Fig.ZA-3 Timing diagram (2)
PS/2 interface timing diagram
In receiving
tWH tWL
0.8VCC 0.2VCC 0.2VCC
CLK
0.8VCC
tsu
0.8VCC
th
0.8VCC 0.2VCC
DATA
0.2VCC
In transmitting
tWL
0.8VCC
tWH
0.8VCC 0.2VCC
CLK
0.2VCC
0.2VCC
td
tv
0.8VCC 0.2VCC 0.8VCC 0.2VCC
DATA
Fig.ZA-4 Timing diagram (3)
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z page 232 of 266
M16C/6KA Group
Timing
LPC bus interface/serial interrupt output timing
tC(CLK) tWH(CLK) VIH VIL tWL(CLK)
LCLK
tsu(D-C)
th(C-D)
LAD[3:0] SERIRQ,CLKRUN,LFRAME (Input)
tv(C-D)
LAD[3:0] SERIRQ,CLKRUN,LFRAME (Active output)
toff(A-F)
LAD[3:0] SERIRQ,CLKRUN,LFRAME (Floating output )
Fig.ZA-5 Timing diagram (4)
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 233 of 266
M16C/6KA Group
Flash memory version
Feature Outline
Table AB-1 shows the feature outline of M16C/6KA (build-in NEW DINOR flash memory version). Table.AB-1 Feature outline of M16C/6KA (build-in NEW DINOR flash memory version)
Item Power supply voltage Power supply voltage for program/erase Flash memory operation mode Erase block division User ROM area Boot ROM area Program method Erase method Program/ erase control method Number of command Program/ erase count ROM code protect User ROM area Boot ROM area Feature 3.0-3.6V (f(XIN)=16MHz, 0 wait) 3.0-3.6V 3 modes (parallel I/O, standard serial I/O, CPU reprogram) 6 division (32K+32K+32K+16K+8K+8K bytes) 1 division (4K bytes) (Note1) 2-byte unit Block erase Program/ erase controlled by s/w commands 5 commands 100 times 100 times Support for parallel I/O and standard serial I/O modes
Note1: The control program for standard serial I/O mode is stored in boot ROM area when shipping from factory. The area can only be erased or programmed by parallel I/O mode.
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 234 of 266
M16C/6KA Group
Flash memory version
Flash Memory
The M16C/6KA (build-in flash memory version) contains the NEW DINOR type flash memory, which is applied VCC=3.3V when using CPU reprogram or standard serial I/O mode. For the flash memory, 3 flash memory modes are available in which to read, program and erase. They are parallel I/O mode, standard serial I/O mode and CPU reprogram mode. For parallel I/O mode, a programmer is used. For standard serial I/O and CPU reprogram modes, the flash memory is manipulated by CPU. Each mode is detailed in the pages to follow. Fig. AB-1 shows that flash memory is divided into several blocks. Erasing is in block unit. In addition to the ordinary user ROM area there is a boot ROM area to store the control program for the CPU reprogram and standard serial I/O modes. The control program for standard serial I/O mode is stored in boot ROM area when shipping from factory. User can reprogram the program to suit its own application system. The area can only be erased or programmed by parallel I/O mode.
0E000016
Block 5 : 32K bytes
0E800016
Block 4 : 32K bytes
0F000016
Block 3 : 32K bytes
0F800016
Block 2 : 16K bytesc
0FC00016
Block 1 : 8K bytes
0FE00016
Block 0 : 8K bytes
0FFFFF16
0FF00016 0FFFFF16
4K bytes Boot ROM area (Note 1)
User ROM area
Note 1: Boot ROM area can be reprogrammed only in parallel I/O mode. (Access to any other areas is inhibited.) Note 2: To specify a block, use the maximum even address in the block.
Fig.AB-1 Block diagram of flash memory version
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 235 of 266
M16C/6KA Group
CPU Reprogram Mode
CPU reprogram mode
In CPU reprogram mode, the on-chip flash memory can be operated on (read, program or erase) under the control of CPU. In CPU reprogram mode, only the user ROM area shown in Fig.AB-1 can be reprogrammed. The boot ROM area cannot be reprogrammed. Make sure the program and block erase commands are issued only for each block of the user ROM area. There are erase write mode 0 (EW0 mode) and erase write mode 1 (EW1 mode) in CPU reprogram mode. Table BB-1 shows the difference between EW0 mode and EW1 mode.
EW0 mode
The microcomputer is placed in CPU rewrite mode by setting the FMR0 register's FMR01 bit to "1" (CPU reprogram mode enabled), ready to accept commands. In this case, because the FMR1 register's FMR11 bit=0, EW0 mode is selected. The FMR01 bit can be set to "1" by writing "0" and then "1" in succession. Use software commands to control program and erase operations. Read the FMR0 register or status register to check the status of program or erase operation completion.
EW1 mode
EW1 mode is selected by setting FMR11 bit to "1" (by writing "0" and then "1" in succession) after setting the FMR01 bit to "1" (by writing "0" and then "1" in succession). Read the FMR0 register to check the status of program or erase operation at completion. The status register can not be read during EW1 mode.
Microcomputer mode and Boot mode
The control program for CPU reprogram mode must be written into the user ROM or boot ROM area in parallel I/O mode beforehand. (If the control program is written into the boot ROM area, the standard serial I/ O mode becomes disable.) See Fig.AB-1 for details about the boot ROM area. Normal microcomputer mode is entered when reset with pulling "L" of M0. In this case, the CPU starts operating the control program in user ROM area. If the microcomputer is reset with M0 being "H" and M1 being "L", the CPU starts operating the control program in boot ROM area. This mode is called as "boot" mode.
Block address
Block address refers to the maximum even address of each block. The address is used in block erase command.
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 236 of 266
M16C/6KA Group
CPU Reprogram Mode
Table BB-1 The list of software command (CPU reprogram mode) Item Operation mode The area, which the reprogram control program can be allocated The area, which the reprogram control program can be executed Reprogramable area EW0 mode *Single chip mode *Boot mode *User ROM area *Boot ROM area Should be transferred to RAM and then executed *User ROM area EW1 mode *Single chip mode *User ROM area
*Can be executed in User ROM area
The limitation of software command
No
The mode after program erase CPU status during auto programming auto erasing The check of the status of flash memory
Read status register mode Operate
*Check FMR00, FMR06, FMR07 bits of FMR0 register by S/W *Execute the read status register command, and then check SR7, SR5 and SR4 bit of status register
_______
*User ROM area However, the block, which the reprogram control program is allocated, is excluded. *Program block area command Inhibited to the block, which reprogram control program is allocated *Read status register command Inhibited Read array mode Hold status (the status of I/O ports is hold the same before executing the command) (Note 1) *Check FMR00, FMR06, FMR07 bits of FMR0 register by S/W
Note1:Do not use interrupts (exclude NMI and WDT).
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 237 of 266
M16C/6KA Group
CPU Reprogram Mode
Feature Outline (CPU reprogram mode)
In CPU reprogram mode, the writing and reading of the commands and data should be in even address ("0" for byte address A0) in 16-bit unit, so the 8-bit unit S/W commands should be written in even address. Commands are ignored with odd address. Fig.BB-1 shows the flash recognition register, the flash control register 0 and the flash control register 1. Bit 0 of flash control register 0 is the RY/BY status flag exclusively used to read the operating status of the flash memory. During programming and erasing operation, it is "0", otherwise it is "1". Bit 1 of flash control register 0 is EW0 mode selection bit. When setting the bit to "1", EW0 mode is selected _______ and the receiving of software command is possible. Keep NMI pin to "H" for the setting. For setting the bit to "1", it is necessary to set the bit to "0" and then to "1" in secession. For setting "0", only set the bit to "0". Bit 3 of flash control register 0 is the flash memory reset bit used to reset the control circuit of the on-chip flash memory. The bit is used when exiting EW0 mode and when flash memory access has failed. When EW0 mode selection bit is "1", writing "1" to the bit resets the control circuit. Bit 5 of the flash control register 0 is the user ROM selection bit. It is enabled only in boot mode. When the bit is set to "1", the accessed area is switched from boot ROM to user ROM. When CPU reprogram mode is entered in boot mode, set this bit to "1". The bit is disabled when program starts in user ROM. When in boot mode, the function of the bit is enabled regardless the CPU rewrite mode. Write the bit with the program that is not located in on-chip flash memory area. Bit 6 of the flash control register 0 is a read only bit indicating the status of auto program operation. The bit is set to "1" when a program error occurs. Otherwise, it is cleared to "0". Bit 7 of the flash control register 0 is a read only bit indicating the status of auto erase operation. The bit is set to "1" when a erase error occurs. Otherwise, it is cleared to "0". Fig. BB-2 and Fig. BB-3 show the flow charts of the setting/resetting for EW0 mode and EW1 mode respectively. The operation specified in the flow chart should be followed. Bit 1 of flash control register 1 is EW1 mode selection bit. When setting the bit to "1", EW1 mode is selected
________
and the receiving of software command is possible. Keep NMI pin to "H" for the setting. For setting the bit to "1", the EW0 mode selection bit should be "1" and it is necessary to set the bit to "0" and then to "1" in succession. For setting to "0", only set the bit to "0". In the case that EW1 selection bit is set to "1" (both EW0 and EW1 mode selection bits are set to "1"), if writing "0" to EW0 mode selection bit, both EW0 and EW1 mode selection bits are cleared to "0".
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 238 of 266
M16C/6KA Group
CPU Reprogram Mode
Flash memory control register 0
b7 b6 b5 b4 b3 b2 b1 b0
Symbol
FMR0 Bit symbol
Address
03B716
When reset
XX0000012
0
0
Bit name RY/BY signal status bit EW0 mode selection bit (Note1)
Function 0: Busy (be written and erased) 1: Ready 0: Normal mode (S/W command disable) 1: EW0 mode (S/W command enable) Must be "0". 0: Normal operation 1: Reset Must be "0".
R RW
FMR00 FMR01
Reserved bit FMR03 Flash memory reset bit (Note 2)
Reserved bit FMR05
User ROM area selection bit 0: Access to boot ROM area (Note 3) 1: Access to user ROM area (Only enabled in boot mode) Program status flag (Note 4) Erase status flag (Note 4) 0: Terminate normally 1: Terminate in error 0: Terminate normally 1: Terminate in error
FMR06 FMR07
Note 1: To write "1" to the bit, it is necessary to write "0" and "1" in succession. Otherwise the bit will not be "1". Do not enter interrupt. Note 2: It is enabled only EW0 mode selection bit is "1". After setting to "1"(reset), please write "0" in succession. Note 3: Please write this bit with program that is not located in on-chip flash memory area.
Flash memory control register 1
b7 b6 b5 b4 b3 b2 b1 b0
Symbol
FMR1 Bit symbol
Address
03B516
When reset
000XXX0X2
00
0
Bit name
Function Uncertain in read. 0: EW0mode 1: EW1 mode Uncertain in read. Must be "0".
RW RW
Reserved bit FMR11 EW1 mode selection bit(Note1)
Reserved bit Reserved bit
Note 1: To write the bit to "1", the status of FMR01 should be "1" and it is necessary to write "0" and then "1" in succession. Do not enter interrupt before writing "1". Keep NMI pin to "H" at setting of the bit. If writing "0" to FMR01, both FMR01 and FMR11 are cleared to "0".
Flash memory identification register
b7 b6 b5 b4 b3 b2 b1 b0
Symbol
FTR
Address
03B416
When reset
XXXXXX112
Function
The value after reset XXXXXX112 : M16C/6KA Group XXXXXX102 : M16C/6K9 Group 000000002 : M16C/6K7 Group XXXX00012 : M16C/6K5 Group (Note) Note: Address 03B416 of M16C/6K5 Group is the flash memory control register.
RW
Fig.BB-1 The structure of flash memory control register and flash memory identification register
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z page 239 of 266
M16C/6KA Group
CPU Reprogram Mode
EW0 mode procedure
Program located in ROM Program located in RAM
Start
*1
Single-chip mode or boot mode
(Only for boot mode) Set user ROM area selection bit to "1"
The setting of processor mode register (Note 1)
Set EW0 mode selection bit="1" (write "0" and then write "1") (Note 2)
Transfer reprogram control program to on-chip RAM
To erase and program with S/W command.
Jump to the reprogram control program, which has been transferred to RAM. (The subsequent processing is executed by the reprogram control program in RAM.)
Reset with read array command or the setting of flash memory reset bit (write "0" and then write "1") (Note 3)
*1
Write "0" to EW0 mode selection bit.
(Only for boot mode) Write user ROM area selection bit to "0". (Note 4)
End Note 1: Set the internal clock frequency as shown below using the main clock division ratio selection bits (bit 6 of address 000616, bit 6 and bit 7 of address 000716):No exceeding 8MHz if wait bit (bit 7 of address 000516)="1". (with wait for internal accessing.) Note 2: For writing "1" to the bit, it is necessary to write "0" and "1" in succession. Otherwise the bit will not be "1". Do not enter interrupt. The write to the bit should be executed other than the flash memory area and MNI pin should be in "H" state. Note 3: Be sure to execute a read command or set flash memory reset bit before exiting the CPU reprogram mode after the completion of earse or program operation. Note 4: The bit can remain "1". In this case, user ROM area will be accessed.
Fig.BB-2 CPU reprogram mode 0 set/reset flowchart
EW1 mode procedure
Program located in ROM Start
Single-chip mode (Note 1)
The setting of processor mode register (Note 2)
After setting EW0 mode selection bit ="1", set EW1 mode selection bit = "1". (Write "0" and then write "1") (Note 3)
To erase and program with S/W command.
Write "0" to EW0 mode selection bit.
End
Note 1: Do not set EW1 mode in boot mode. Note 2: For CPU reporgram mode, set the internal clock frequency as shown below using the main clock division ratio selection bits (bit6 of address 000616, bit 6 and bit 7 of address 000716) Wait bit (bit 7 of address 000516) = "1" (with wait for internal accessing.) and not exceeding 4MHz. Note 3: For writing "1" to EW0, EW1 mode selection bits, it is necessary to write "0" and "1" in succession. Otherwise the bits will not be "1". Do not enter interrupt.
Fig.BB-3 CPU reprogram mode 1 set/reset flowchart
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z page 240 of 266
M16C/6KA Group
CPU Reprogram Mode
Precautions on CPU reprogram mode
Described below are the precautions to be observed in programming the flash memory in CPU reprogram mode. (1) Operation speed During CPU reprogram mode, set the internal clock frequency as shown below using the main clock divide ratio select bits (bit 6 at address 000616 and bit 6 and 7 at address 000716): * EW0 mode Not exceeding 8MHz if wait bit (bit 7 of address 000516) = "1". (with wait for internal accessing) * EW1 mode Not exceeding 4MHz if wait bit (bit 7 of address 000516) = "1". (with wait for internal accessing) (2) Instructions inhibited against use The instructions listed below cannot be used during CPU reprogram mode because they refer to the internal data of the flash memory: UND instruction, INTO instruction, JMPS instruction, JSRS instruction and BRK instruction (3) Interrupts inhibited against use
_______
The NMI, address match and WDC interrupts cannot be used during CPU reprogram mode because they refer to the internal data of the flash memory. If interrupts have their vectors in the variable vector table, they can be used by transferring the vector into the RAM area. (4) Reset The reset is always receivable. (5) The reprogram in user ROM area When CPU reprogram mode is entered and the block that the flash reprogram control program is located is being reprogramming, the block may not be reprogrammed correctly if the power supply is suddenly down. It is possible that the flash reprogram cannot be executed again in this case. Thus, it is recommended to use standard serial I/O mode and parallel I/O mode.
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 241 of 266
M16C/6KA Group
CPU Reprogram Mode
Software commands
Table BB-2 lists the S/W commands available. In CPU reprogram mode, the S/W commands can be used to specify the erase or program operation. Note that when entering a S/W command, the upper byte (D15-D8) is ignored. The content of each S/W command is explained below.
Table BB-2 List of software commands (CPU reprogram mode) The 1st bus cycle Cycle Command Data Mode Address number (D15-D0) Read array 1 Write X (Note 5) FF16 Read status register 2 Write X 7016 Clear status register 1 Write X 5016 Program 2 Write X 4016 Block erase 2 Write X 2016
The 2nd bus cycle Data Mode Address (D15-D0) Read Write Write X WA(Note 3) BA(Note 4) SRD(Note 2) WD(Note 3) D016
Note 1: When a S/W command is input, the high-order byte of the data(D15-D8) is ignored. Note 2: Note 3: Note 4: Note 5: SRD = Status Register Data. The address should be even and within the user ROM area. WA = Write Address, WD = Write Data BA = Block Address (the maximum even address of the block) "X" can be any even address in user ROM area.
Read Array Command (FF16) Issuing the command code "FF16" in the 1st bus cycle enters the read array mode. When an even address is issued in one of the bus cycle that follows, the content of the address is read out at the data bus (D15-D0), 16 bits at a time. The read array mode is retained intact until another command is written. Read Status Register Command (7016) When the command code "7016" is issued in the 1st bus cycle, the content of the status register is read out at the data bus (D7-D0) by a read in the 2nd bus cycle. (The odd address in user ROM area should be specified.) The status register is explained in the next section. Clear Status Register Command (5016) The command is used to clear the bits SR4 and SR5 of the status register after they have been set. These bits indicate that operation has ended in error. To use this command, issue the command code "5016" in the 1st bus cycle.
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 242 of 266
M16C/6KA Group
CPU Reprogram Mode
Program Command (4016) Program operation starts when the command code "4016" is issued in the 1st bus cycle. If the address and data are issued in the 2nd bus cycle, program operation (data programming and verification) will start. _____ Whether the program operation is completed can be conformed by reading the status register or the RY/BY status flag. When the program starts, the read status register mode is accessed automatically and the content of the status register can be read on the date bus (D7-D0). The status register bit 7 (SR7) is set to "0" at the same time when the program operation starts and is returned to "1" upon the completion of the program operation. In this case, the read status register mode remains active until the Read Array Command (FF16) is issued. _____ The RY/BY status flag is "0" during program operation and "1" when the program operation is completed same as the status register bit 7. After the program, reading the status register can check the result. Refer to the section where the status register is detailed.
Start
Write 4016
Write Write address Write data (The address for reading the status register should be even and within the user ROM area.)
Status register read
SR7=1? or RY/BY=1?
NO
YES NO
SR4=0?
Program error
YES Program completed
Fig.BB-4 Program flowchart
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 243 of 266
M16C/6KA Group
CPU Reprogram Mode
Block Erase Command (2016/D016) By issuing the command code "2016" in the 1st bus cycle and the conformation command code "D016" and block address in the 2nd bus cycle, the erase operation specified by the block address starts (erase and erase verification). _____ Whether the block erase command is terminated can be conformed by reading the status register or the RY/BY status flag. When the block erase operation starts, the read status register mode is accessed automatically and the content of the status register can be read out. The status register bit 7 (SR7) is set to "0" at the same time when the erase operation starts and is returned to "1" upon the completion of the erase operation. In this case, the read status register mode remains active until the Read Array Command (FF16) is written. _____ The RY/BY status flag is "0" during erase operation and "1" when the erase operation is completed the same as the bit 7 of status register. After the block erase, reading the status register can check the result. Refer to the section where the status register is detailed. Block Erase Command is inhibited to the block, which reprogram control program is allocated.
Start
Write 2016
Write D016 Block address (The address for reading the status register should be even and within the user ROM area.)
Status register read
SR7=1? or RY/BY=1?
NO
YES
Full status check (Note 1)
Error
Erase error
Erase completed
Note 1: Refer to Fig. BB-6
Fig.BB-5 Erase flowchart
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 244 of 266
M16C/6KA Group
CPU Reprogram Mode
Status register
The status register shows the operation status of the flash memory and whether program and erase operations end successfully or not. It can be read in the following conditions. (1) By reading an arbitrary address from the user ROM area after issuing the read status register command (7016). (2) By reading an arbitrary address from the user ROM area in the period from the start of program or erase operation to the execution of read array command (FF16). Table BB-2 shows the status register. The status register can be cleared in the following condition. (1) By issuing the clear status register command (5016). (2) After reset, the status register is set to "8016". Each bit of the register is shows below. Sequencer status (SR7) After power-on, the sequencer status is set to "1" (ready). The bit is set to "0" (busy) during program and erase operations and is set to "1" upon the completion of these operations. Erase status (SR5) Erase status indicates the status of erase operation. When erase error occurs, it is set to "1". The bit becomes "0" when it is cleared. Program status (SR4) Program status indicates the status of program operation. When program error occurs, it is set to "1". The bit becomes "0" when it is cleared. If "1" is set to SR5 or SR4, the program and block erase operations are not accepted. Before execution of these commands, it is necessary to execute the clear status register command (5016) to clear the status register. If any S/W commands are not correct, both the SR5 and SR4 are set to "1".
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 245 of 266
M16C/6KA Group
CPU Reprogram Mode
Table BB-3 Definition of each bit of status register
Each bit of SRD SR7 (bit7) SR6 (bit6) SR5 (bit5) SR4 (bit4) SR3 (bit3) SR2 (bit2) SR1 (bit1) SR0 (bit0) Reserved
Status name Sequencer status Erase status Program status Reserved Reserved Reserved Reserved
Definition "1" Ready Terminated in error Terminated in error "0" Busy Terminated normally Terminated normally -
Full status check By performing full status check, the execution result of erase and program operations can be known. Fig.BB-6 shows the full status check flowchart and the method to deal with the error.
Read status register
SR4=1 and SR5=1? NO SR5=0? YES SR4=0? YES
YES
Command sequence error
Execute the clear status register command (5016) to clear the status register. Try to perform the operation again after conforming that the command is entered correctly.
NO
Block erase error
Should block erase error occur, the block cannot be used.
NO
Program error
Should program error occur, the block cannot be used.
End (block erase, program)
Note: When SR5 or SR4 is set to "1", neither of the program nor block erase commands are accepted. Execute the clear status register command (5016) before executing these commands.
Fig.BB-6 Full status check flowchart and the method to deal with errors
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 246 of 266
M16C/6KA Group
Functions To Inhibit Rewriting Flash Memory
Functions to inhibit rewriting to the on-chip flash memory
To prevent flash memory from being miss-read or miss-written, ROM code protect function for parallel I/O mode and ID code check function for standard serial mode are introduced. ROM code protect function ROM code protect function can inhibit readout from or modification to the flash memory by setting the content in ROM code protect control address (0FFFFF16) for parallel I/O mode. Fig.BB-7 shows the content of ROM code protect control address (0FFFFF16). (The address exists in user ROM area.) If one of the pair of ROM code protect bits is set to "0", ROM code protect is turned on, so that the flash memory is protected against the readout or modification. ROM code protect is implemented in two levels. If level 2 is selected, the flash memory is protected even against readout by a shipment inspection LSI tester, etc. When both level 1 and level 2 are set, level 2 will be selected. If both of the two ROM code protect reset bits are set to "00", ROM code protect is turned off, so that the flash memory can be read out or modified. Once ROM code protect is turned on, the ROM code protect reset bits cannot be modified in parallel I/O mode. Use the serial mode or other to rewrite these two bits.
ROM code protect control address
b7 b6 b5 b4 b3 b2 b1 b0
Symbol
ROMCP Bit symbol
Address
0FFFFF16
When reset
FF16
11
Bit name
Function Always set these bits to "1"
b3 b2
Reserved bits
ROMCP2 ROM code protect level 2 set bits (Note 1,2)
0 0: Protect enabled 0 1: Protect enabled 1 0: Protect enabled 1 1: Protect disabled
b5 b4
ROMCR
0 0: Protect removed ROM code protect reset 0 1: Protect set bits effective bits (Note 3) 1 0: Protect set bits effective 1 1: Protect set bits effective
b7 b6
0 0: Protect enabled ROMCP1 ROM code protect level 0 1: Protect enabled 1 0: Protect enabled 1 set bits (Note 1) 1 1: Protect disabled Note 1: When ROM code protect is turned on, the on-chip flash memory is protected against readout or modification in parallel I/O mode. Note 2: When ROM code protect level 2 is turned on, ROM code readout by a shipment inspection LSI tester,etc. is also inhibited. Note 3: The ROM code protect reset bits can be used to turn off ROM code protect level 1 and level 2. However,Since these bits can not be modified in parallel I/O mode, they should be rewritten in serial I/O mode or other modes.
Fig.BB-7 ROM code protect control address
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 247 of 266
M16C/6KA Group
Functions To Inhibit Rewriting Flash Memory
ID code check function
The function is used in standard serial I/O mode. If the flash memory is not blank, the ID code sent from serial burner is compared with that inside flash memory to check the agreement. It the ID codes do not match, the commands from serial burner are not accepted. Each ID code consists of 8-bit data, the areas of which, beginning from the 1 st byte, are 0FFFDF16, 0FFFE316, 0FFFEB16, 0FFFEF16, 0FFFF316, 0FFFF716, 0FFFFB16. Write a program with the ID code at these addresses to the flash memory.
Address 0FFFDC16 to 0FFFDF16 0FFFE016 to 0FFFE316 0FFFE416 to 0FFFE716 0FFFE816 to 0FFFEB16 0FFFEC16 to 0FFFEF16 0FFFF016 to 0FFFF316 0FFFF416 to 0FFFF716 0FFFF816 to 0FFFFB16 0FFFFC16 to 0FFFFF16 ID3 ID4 ID5 ID6 ID7 ID1 ID2 Undefined instruction vector Overflow vector BRK instruction vector Address match vector Single step vector Watchdog timer vector DBC vector NMI vector Reset vector
4 bytes
Fig.BB-8 ROM ID code addresses
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 248 of 266
M16C/6KA Group
Prallel I/O mode
Parallel I/O mode
Parallel I/O mode is to input and output the software command, address and data in parallel to access the on-chip flash memory (read, program, erase etc.). Please use the specific device (programmer) supported for M16C/6KA Group. Referring to the guideline etc. of each device manufacture for the usage.
User ROM area and boot ROM area
In parallel I/O mode, both user ROM area and boot ROM area showed in Fig.AB-1 can be reprogrammed. The access method to both areas is the same. The size of boot ROM area is 4K bytes. The addresses are allocated in 0FF00016- 0FFFFF16. Make sure program and block erase operations are always performed within this address range. (Access to any location outside this address range is prohibited.) In the boot ROM area, erase block operation is applied to only one 4K bytes block. The boot ROM area has had a standard serial I/O mode control program stored in it when shipped from Renesas factory. Therefore, if the standard serial I/O mode is used, the rewriting to the boot ROM area is not necessary.
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 249 of 266
M16C/6KA Group
Standard Serial I/O Mode
Table EE-1 Pin function (Flash memory standard serial I/O mode) Pin name VCC, VSS M0 ____________ RESET XIN XOUT M1 AVCC, AVSS VREF P00-P07 P10-P17 P20-P27 P30-P37 P40-P47 P50-P57 P60-P63 P64 P65 P66 P67 P70-P77 P80-P84 P86,P87 P85 P90-P97 P100-P107 P110-P117 P120-P127 P130-P137 P140-P147 P150-P157 P160,P161 Name Power supply M0 Reset input Clock input Clock output M1 Analog power supply Reference voltage Input port P0 Input port P1 Input port P2 Input port P3 Input port P4 Input port P5 Input port P6 BUSY output SCLK input RXD input TXD input Input port P7 Input port P8
______
I/O I I I O I I I I I I I I I O I I O I I I I I I I I I I I Apply 3.3 0.3V to VCC, apply 0V to VSS Connect to VCC Reset input pin. While reset is "L", 20 cycles or more clocks input to XIN pin are needed. Connect a ceramic resonator or crystal oscillator between XIN and XOUT. If external clock is used, input it to XIN pin and open the XOUT pin. Connect to VSS Connect AVSS to VSS, AVCC to VCC The input pin of reference voltage of AD converter Input "H", "L" or open Input "H", "L" or open Input "H", "L" or open Input "H", "L" or open Input "H", "L" or open Input "H", "L" or open Input "H", "L" or open The output pin of BUSY signal The input pin of serial clock The input pin if serial data The output pin of serial data Input "H", "L" or open Input "H", "L" or open Connect to VCC Input "H", "L" or open Input "H", "L" or open Input "H", "L" or open Input "H", "L" or open Input "H", "L" or open Input "H", "L" or open Input "H", "L" or open Input "H", "L" or open
NMI input Input port P9 Input port P10 Input port P11 Input port P12 Input port P13 Input port P14 Input port P15 Input port P16
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 250 of 266
M16C/6KA Group
Standard Serial I/O Mode
108 107 106 105 104 103 102 101 100 99
84 83
98 97 96 95 94 93 92 91 90 89 88 87 86 85
82 81 80
P10 P126 P125/INT111 P124/INT102 P123/INT92 P122/INT82 P121/INT72 P120/INT61 P07 P06 P05 P04 P03 P02 P01 P00 P117 P116 P115 P114 P113 P112 P111/F1OUT1 P110/F1OUT0 P107/AN7/INT110 P106/AN6/INT100 P105/AN5/INT90 P104/AN4/INT80 P103/AN3/INT70 P102/AN2 P101/AN1 AVSS P100/AN0 VREF AVcc P97/ADTRG/SIN40/INT60
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 25 1 26 1 27 1 128 129 130 131 132 133 134 135 136 137 138 139 40 1 41 1 42 1 143 144 1 2345 678 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
79 78 77 76 75 74 73
72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37
P11 P12 P13 P14/INT71/CTS11/RTS11/CLKS11 P15/INT81/CLK11 P16/INT91/RXD11 P17/INT101/TXD11 P20/TXD21 P21/RXD21 P22/CLK21 P23/CTS21/RTS21 P24 P25 P26 P27 VSS P30/LAD0 VCC P127 P31/LAD1 P32/LAD2 P33/LAD3 P34/LFRAME P35/LRESET P36/LCLK P37 P130 P131 P132 P133 P134 P135 P136 P137 P40/ TA00OUT/OBF00/PWM41 P41/TA10OUT/PWM51
M306KAFCLRP (144PFB)
P42/TA20OUT/GATEA20 P43/OBF01 P44/PWM01/OBF1 P45/PWM11/OBF2 P46/PWM21/OBF3 VCC P47/PWM31 VSS P140/KI10 P141/KI11 P142/KI12 P143/KI13 P144/KI14 P145/KI15 P146/KI16 P147/KI17 P50/KI00 P51/KI01 P52/KI02 P53/KI03 P54/KI04 P55/KI05 P56/KI06 P57 /CLKOUT/KI07 P150/TA01OUT P151/TA11OUT P152/TA21OUT P60/SDA0 P61/SCL0 P62/SDA10 P63/SCL10 P64/CTS10/RTS10/CLKS10 P65/CLK10 P66/RXD10/TA3OUT P67/TXD10/TA4OUT P70/PS2A0
BUSY SCLK RXD TXD
P96/ANEX1/SOUT40/PWM30 P95/ANEX0/CLK40/PWM20 P94/TB40IN/PWM10 P93/TB30IN/PWM00
P92/SOUT30/INT5 P91/SIN30/INT4 P90/CLK30/INT3 P161/TB41IN/PWM50 P160/TB31IN/PWM40 P157/SIN41 P156/SOUT41 P155/CLK41 P154 P153 M1 M0 P87 P86 RESET XOUT VSS XIN VCC P85/NMI P84/TB2IN/SCL21 P83/TB1IN/SDA21 P82/TB0IN/SCL11 P81/TA4IN/SDA11 P80/ICCK P77/TA3IN/SCL20 P76/SDA20 P75/TA2IN/INT2/PS2B2 P74/INT1/PS2B1 P73/TA1IN/INT0/PS2B0 P72/PS2A2 P71/TA0IN/TB5IN/PS2A1
VSS VCC
RESET
Connect to oscillation circuit
Mode setting method Name of signal line Value M0 M1 RESET VCC VSS VSS VCC
Fig.EE-1 Pin connections for serial I/O mode
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 251 of 266
M1 M0
M16C/6KA Group
Standard Serial I/O Mode
Standard serial I/O mode
The standard serial I/O mode inputs and outputs the S/W commands, addresses and data needed to operate (read, program, erase etc.) the on-chip flash memory with a dedicated serial programmer. Different from parallel I/O mode, in standard serial mode, CPU controls the flash memory reprogramming (uses the CPU reprogram mode) and the input of serial reprogram data etc. The standard serial I/O mode is started by connecting M0 to "H", M1 to "L" with the release of reset. (To connect M0 to "L" in normal microcomputer mode.) This control program is written in boot ROM area when the product is shipped from Renesas factory. Make sure that the standard serial I/O mode cannot be used if boot ROM area is written in parallel I/O mode. Fig EE-1 shows the pin connections for standard serial I/O mode. The input and output of serial data are processed in CLK10, RxD10, TxD10, RTS10 (BUSY) 4 pins of the UART1. The CLK10 is clock input pin, which clock is input externally. The TxD10 is CMOS output pin. The RTS10 (BUSY) pin outputs "L" when ready for reception and outputs "H" when reception starts. The serial data are transferred in 8-bit unit. In standard serial I/O mode, only the user ROM area shown in Fig.AB-1 can be reprogrammed. Boot ROM area cannot be reprogrammed. In the standard serial I/O mode, a 7-byte ID code is used. If the flash memory is not blank, commands sent from programmer are not accepted unless the ID code matches.
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 252 of 266
M16C/6KA Group
Standard Serial I/O Mode
Outline (standard serial I/O mode)
In standard serial I/O mode, S/W commands, addresses, and data etc. are input and output with the peripheral device (serial programmer) using 4-wire clock-synchronized serial I/O (UART1). In reception, S/W commands, addresses and program data are read from RxD10 pin synchronized with the rising edge of the transfer clock that is input to the CLK10 pin. In transmission, the read data and status are output to TxD10 pin synchronized with the falling edge of the transfer clock. The TxD10 is CMOS output pin. Transfer is in 8-bit unit with LSB first. During transmission, reception, erasing and programming, the RTS10 (BUSY) pin is "H". Accordingly, always start the next transfer after the RTS10 (BUSY) pin becomes "L". The read after the input of S/W commands can get memory data and status register. Reading the status register can check the flash memory operation status, the normal/error end of erasing or programming operation. The following are the explanation of S/W commands, status register etc.
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 253 of 266
M16C/6KA Group
Standard Serial I/O Mode
S/W commands
Table EE-2 lists the S/W commands. In standard serial I/O mode, the S/W commands, which transferred from RxD pin, control of erase, program and read etc. The S/W commands in standard serial I/O mode are similar with that in parallel I/O mode. ID check function, download function, version information output function, boot ROM area output function and read check data, 5 commands are added. Table EE-2 The list of S/W commands (standard serial I/O mode)
Control 1 2 3 4 5 6 7 8 9 command Page read Page program Block erase Read status register Clear status register ID check function Download function Version information output function Boot ROM area 1st byte transfer FF16 4116 2016 7016 5016 F516 FA16 FB16 FC16 FD16 Address (low) Address (low) Version data output Address (middle) Check data (low) Address (middle) Address (high) Version data output Address (high) Check data (high) Address (high) Check sum Version ID size Data input Version ID1 No. of times required Version -9th byte data output Data output Version data output -259th byte data output Not acceptable -ID7 2nd byte Address (middle) Address (middle) Address (middle) SRD output 3rd byte Address (high) Address (high) Address (high) SRD1 output Not acceptable Acceptable Not acceptable Acceptable Not acceptable 4th byte Data output Data input D016 5th byte Data output Data input 6th byte Data output Data input - 259th byte data output 259th byte data input Not acceptable Acceptable If ID unmatched Not acceptable Not acceptable
data output data output Data Data output output
output function 10 Read check data
Note 1: Shading indicates transfer from flash memory on chip microcomputer to serial programmer. The else indicates transfer from serial programmer to flash memory on chip microcomputer. Note 2: SRD means status register data. SRD1 means status register 1 data. Note 3: All commands are acceptable if the flash memory is blank.
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 254 of 266
M16C/6KA Group
Standard Serial I/O Mode
The following are the descriptions of S/W commands
Page read command The command reads the specified page (256 bytes) of the flash memory sequentially one byte at a time. Execute the page read command as following: (1) Transfer the "FF16" command code in the 1st byte. (2) Transfer addresses A8- A15 and A16- A23 in the 2nd and 3rd byte respectively. (3) From the 4th byte onward, data (D7-D0) of the page specified by the address (A23-A8) will be output sequentially from the smallest address sync with the falling edge of the clock.
CLK10 A16 to A23
RxD10
(M16C reception data)
FF16
A8 to A15
TxD10
(M16C transmit data)
Data0
Data255
RTS10(BUSY)
Fig.EE-2 Timing of page read Read status register command The command is for reading status information. When command code "7016" is sent in the 1st byte, the contents of status register (SRD) and status register 1 (SRD1) will be output in the 2nd and 3rd byte respectively sync with the falling edge of the clock.
CLK10
RxD10
(M16C reception data)
7016
TxD10
(M16C transmit data)
SRD output
SRD1 output
RTS10(BUSY)
Fig.EE-3 Timing of read status register
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 255 of 266
M16C/6KA Group
Standard Serial I/O Mode
Clear status register command The command clears the bits (SR4-SR5), which are set when operation ended in error. When command code "5016" is sent in the 1st byte, the aforementioned bits are cleared. When the clear status register operation ends, the RTS10 (BUSY) signal changes from "H" to "L".
CLK10
RxD10
(M16C reception data)
5016
TxD10
(M16C transmit data)
RTS10(BUSY)
Fig.EE-4 Timing of clear status register Page program command The command programs the specified page (256 bytes) of flash memory sequentially one byte a time. Execute the command as follows: (1) Transfer the command code "4116" in the 1st byte. (2) Transfer addresses A15-A8 and A23-A16 in the 2nd and 3rd bytes respectively. (3) From the 4th byte onward, after inputting 256 bytes program data (A7-A0) from the smallest address of the specified page, the page program operation will be executed automatically. When the reception for the next 256 bytes is setup, the RTS10 (BUSY) signal changes from "H" to "L". The result of the page program can be known by reading the status register. For more detail, see the section on the status register.
CLK10
RxD10
(M16C reception data)
4116
A8 to A15
A16 to A23
Data0
Data255
TxD10
(M16C transmit data)
RTS10(BUSY)
Fig.EE-5 Timing of page program
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 256 of 266
M16C/6KA Group
Standard Serial I/O Mode
Block erase command The command erases the data in the specified block. Execute the command as follows: (1) Transfer the command code "2016" in the 1st byte. (2) Transfer addresses A15-A8 and A23-A16 in the 2nd and 3rd bytes respectively. (3) After transferring the verify command code"D016" in the 4th byte, the erase operation starts for the specified block of the flash memory. Issue the biggest address of th2e specified block to A23-A8. After the completion of block erase, the RTS10 (BUSY) signal changes from "H" to "L". The result of the block erase can be know by reading the status register. For more detail, see the section on the status register.
CLK10
RxD10
(M16C reception data)
2016
A8 to A15
A16 to A23
D016
TxD10
(M16C transmit data)
RTS10(BUSY)
Fig.EE-6 Timing of block erase
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 257 of 266
M16C/6KA Group
Standard Serial I/O Mode
Download function The command downloads an execution program to RAM. Execute the command as follows: (1) Transfer the command code "FA16" in the 1st byte. (2) Transfer the program size in the 2nd and 3rd bytes. (3) Transfer the checksum in the 4th byte. Check sum is calculated from all transferred data from the 5th byte onward. (4) The execution program is transferred from 5th byte onward. After the entire program data have been transferred, the downloaded execution program will be executed if the checksum matches. The program size allowed to transfer varies according to the size of on-chip RAM.
CLK10
RxD10
(M16C reception data)
FA16
Data size Data size
(low)
(high)
Check sum
Program data
Program data
TxD10
(M16C transmit data)
RTS10(BUSY)
Fig.EE-7 Timing of download function
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 258 of 266
M16C/6KA Group
Standard Serial I/O Mode
Version information output function The version information of the control program stored in boot ROM area can be output by the function. Execute the command as follows: (1) Transfer the command code "FB16" in the 1st byte. (2) From the 2nd byte onward, the version information will be output. The information is composed of 8 ASCII character code.
CLK10
RxD10
(M16C reception data)
FB16
TxD10
(M16C transmit data)
'V'
'E'
'R'
'X'
RTS10(BUSY)
Fig.EE-8 Timing of version information output function
Boot ROM area output function The control program stored in boot ROM area can be read out in page (256 bytes) unit by the function. Execute the command as follows: (1) Transfer the command code "FC16" in the 1st byte. (2) Transfer addresses A15-A8 and A23-A16 in the 2nd and 3rd bytes respectively. From the 4th byte onward, the data (D7-D0) specified in page (256 bytes) address A23-A8 will be output sequentially from the smallest address in sync with the rising edge of the clock.
CLK10
RxD10
(M16C reception data)
FC16
A8 to A15
A16 to A23
TxD10
(M16C transmit data)
Data0
Data255
RTS10(BUSY)
Fig.EE-9 Timing og boot ROM area output function
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 259 of 266
M16C/6KA Group
Standard Serial I/O Mode
ID check function The command checks the ID code. Execute the command as follows: (1) Transfer the command code "F516" in the 1st byte. (2) Transfer addresses A7-A0, A15-A8 and A23-A16 of 1st ID code (ID1) in the 2nd, 3rd and 4th bytes respectively. (3) Transfer the number of the ID code in the 5th byte. (4) From the 6th byte onward, transfer the IDs from the 1st ID code (ID1).
CLK10
RxD10
(M16C reception data)
F516
DF16
FF16
0F16
IDsize
ID1
ID7
TxD10
(M16C transmit data)
RTS10(BUSY)
Fig.EE-10 Timing of ID check function ID code If the flash memory is not blank, the input ID codes are compared with that written in flash memory. If they do not match, the input commands will not be accepted. Each ID code contains 8 bits data. Beginning from the 1st ID byte, the address of each ID code is 0FFFDF16, 0FFFE316, 0FFFEB16, 0FFFEF16, 0FFFF316, 0FFFF716 and 0FFFFB16 respectively. Write the program with the ID codes in these addresses to the flash memory.
Address 0FFFDC16 to 0FFFDF16 0FFFE016 to 0FFFE316 0FFFE416 to 0FFFE716 0FFFE816 to 0FFFEB16 0FFFEC16 to 0FFFEF16 0FFFF016 to 0FFFF316 0FFFF416 to 0FFFF716 0FFFF816 to 0FFFFB16 0FFFFC16 to 0FFFFF16 ID3 ID4 ID5 ID6 ID7 ID1 ID2 Undefined instruction vector Overflow vector BRK instruction vector Address match vector Single step vector Watchdog timer vector DBC vector NMI vector Reset vector
4 bytes
Fig.EE-11 ID code addressed
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z page 260 of 266
M16C/6KA Group
Standard Serial I/O Mode
Read check data Read check date command is for conforming if the reprogram data sent after page program command have been received correctly. (1) Transfer the command code "FD16" in the 1st byte. (2) Transfer check data (low) and check data (high) in the 2nd and 3rd bytes respectively. When using read check data command, the command should be issued at first to initialize the check data. The next is to issue the page program command and related reprogram data. After that, by issuing the read check data command again, the check data for the reprogram data issued between the two read check data command can be read out. Adding the reprogram data in byte unit and then calculating the lower 2 bytes of the added data in two's complement gives out the check data.
CLK10
RxD10
(M16C reception data)
FD16
TxD10
(M16C transmit data)
Check data (low)
Check data (high)
RTS10(BUSY)
Fig.EE-12 Timing of read check dt command
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 261 of 266
M16C/6KA Group
Standard Serial I/O Mode
Status register Status register indicates if the operation to the flash memory ends successfully or in error. It can be read by issuing the read status register command (7016). The status register can be cleared by issuing the clear status register command (5016). Table EE-3 shows the definition of each bit of the register. After reset, status register outputs "8016".
Table EE-3 Status register (SRD)
Definition Symbol SR7 (D7) SR6 (D6) SR5 (D5) SR4 (D4) SR3 (D3) SR2 (D2) SR1 (D1) SR0 (D0) Status Sequencer status Reserved Erase status Program status Reserved Reserved Reserved Reserved "1" Ready Terminated in error Terminated in error "0" Busy Terminated normally Terminated normally -
Sequencer status (SR7) After power-on, the sequencer status is set to "1" (ready). The bit is set to "0" (busy) during program and erase operations and is set to "1" upon the completion of these operations. Erase status (SR5) Erase status indicates the status of erase operation. When erase error occurs, it is set to "1". The bit becomes "0" when it is cleared. Program status (SR4) Program status indicates the status of program operation. When program error occurs, it is set to "1". The bit becomes "0" when it is cleared.
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 262 of 266
M16C/6KA Group
Standard Serial I/O Mode
Status register 1 (SRD1) Status register 1 indicates the status of serial communication, the result of ID codes comparison, the result of checksum comparison etc. It can be read after SDR by issuing the read status register command (7016). The register can be cleared by issuing the clear status register command (5016). Table EE-4 shows the definition of each bit of the register. After power on, status register 1 outputs "0016". Table EE-4 Status register (SRD1)
Each bit of SRD SR15 (bit7) SR14 (bit6) SR13 (bit5) SR12 (bit4) SR11 (bit3) SR10 (bit2)
Definition Status name Boot update completed bit Reserved Reserved Check sum match bit ID check completed bits Match 00 01 10 11 "1" Update completed Mismatch Not verified Verified with mismatch Reserved Verified with match Normal operation "0" Not update -
SR9 (bit1) SR8 (bit0)
Timeout of data reception Reserved
Timeout
Boot update completed bit (SR15) The flag indicates that if the control program has been downloaded to RAM with download function. Check sum match bit (SR12) The flag indicates if the check sum is matched when downloading the control program with download function. ID check completed bits (SR11, SR10) These bits indicate the result of ID checks. Some commands cannot be accepted without the ID checks. Timeout of data reception bit (SR9) The flag indicates if timeout occurs during data reception. If the bit is set to "1" during data reception, microcomputer will discard the received data and return to wait state.
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 263 of 266
M16C/6KA Group
Standard Serial I/O Mode
Full status check
By performing full status check, the execution result of erase and program operations can be known. Fig.EE13 shows the full status check flowchart and the method to deal with the error.
Read status register
SR4=1 ? and YES SR5=1 ? NO SR5=0? YES SR4=0? YES NO NO
Command sequence error
Execute the clear status register command (5016) to clear the status register. Try to perform the operation again after conforming that the commands is entered correctly. Should block erase error occur, the block can not be used.
Block erase error
Program error
Should program error occur, the block can not be used.
End (block erase, program)
Note: When SR5 or SR4 is set to "1", neither of the program nor block erase commands are accepted. Execute the clear status register command (5016) before executing these commands.
Fig.EE-13 Full status check flowchart and the method to deal with errors
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 264 of 266
M16C/6KA Group
Standard Serial I/O Mode
Circuit applied for standard serial I/O mode (example)
The figure below shows a circuit applied for standard serial I/O mode. The control pins bary by different programmer. Refer to programmer manual for the detail.
Clock input BUSY output Data input Clock output
CLK10 RTS10(BUSY) RXD10 TXD10 M16C/6KA (NEW DINOR type flash memory) M0 M1 NMI
The control pins and external circuitry vary by different programmer. Refer to programmer manual for the detail.
Fig.EE-14 Example circuit applied for the standard serial I/O mode
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 265 of 266
M16C/6KA Group
Package
Package
144PFB-A
MMP
JEDEC Code - Weight(g) 0.62 Lead Material Cu Alloy
Plastic 144pin 16 16mm body TQFP
MD
EIAJ Package Code TQFP144-P-1616-0.40
e
HD D
144 1 109 108
b2
I2 Recommended Mount Pad Symbol A A1 A2 b c D E e HD HE L L1 Lp
A3
36 37 72
73
A L1
e
F
x y b2 I2 MD ME
y
b
x
L Detail F Lp
M
Dimension in Millimeters Min Nom Max - - 1.2 0.05 0.1 0.15 - 1.0 - 0.13 0.18 0.23 0.105 0.125 0.175 15.9 16.0 16.1 15.9 16.0 16.1 0.4 - - 17.8 18.0 18.2 17.8 18.0 18.2 0.4 0.5 0.6 1.0 - - 0.45 0.6 0.75 - 0.25 - - - 0.07 0.08 - - 0 8 - 0.225 - - 1.0 - - - 16.4 - - 16.4 -
HE
E
A2
A1
Rev.1.00 Jul 16, 2004 REJ03B0100-0100Z
page 266 of 266
c
A3
ME
REVISION HISTORY
Rev. Date Page 1.00 Jul 16, 2004 First edition issued
M16C/6KA Group Data Sheet
Description Summary
(1/1)
Sales Strategic Planning Div.
Keep safety first in your circuit designs!
Nippon Bldg., 2-6-2, Ohte-machi, Chiyoda-ku, Tokyo 100-0004, Japan
1. Renesas Technology Corp. puts the maximum effort into making semiconductor products better and more reliable, but there is always the possibility that trouble may occur with them. Trouble with semiconductors may lead to personal injury, fire or property damage. Remember to give due consideration to safety when making your circuit designs, with appropriate measures such as (i) placement of substitutive, auxiliary circuits, (ii) use of nonflammable material or (iii) prevention against any malfunction or mishap. Notes regarding these materials 1. These materials are intended as a reference to assist our customers in the selection of the Renesas Technology Corp. product best suited to the customer's application; they do not convey any license under any intellectual property rights, or any other rights, belonging to Renesas Technology Corp. or a third party. 2. Renesas Technology Corp. assumes no responsibility for any damage, or infringement of any third-party's rights, originating in the use of any product data, diagrams, charts, programs, algorithms, or circuit application examples contained in these materials. 3. All information contained in these materials, including product data, diagrams, charts, programs and algorithms represents information on products at the time of publication of these materials, and are subject to change by Renesas Technology Corp. without notice due to product improvements or other reasons. It is therefore recommended that customers contact Renesas Technology Corp. or an authorized Renesas Technology Corp. product distributor for the latest product information before purchasing a product listed herein. The information described here may contain technical inaccuracies or typographical errors. Renesas Technology Corp. assumes no responsibility for any damage, liability, or other loss rising from these inaccuracies or errors. Please also pay attention to information published by Renesas Technology Corp. by various means, including the Renesas Technology Corp. Semiconductor home page (http://www.renesas.com). 4. When using any or all of the information contained in these materials, including product data, diagrams, charts, programs, and algorithms, please be sure to evaluate all information as a total system before making a final decision on the applicability of the information and products. Renesas Technology Corp. assumes no responsibility for any damage, liability or other loss resulting from the information contained herein. 5. Renesas Technology Corp. semiconductors are not designed or manufactured for use in a device or system that is used under circumstances in which human life is potentially at stake. Please contact Renesas Technology Corp. or an authorized Renesas Technology Corp. product distributor when considering the use of a product contained herein for any specific purposes, such as apparatus or systems for transportation, vehicular, medical, aerospace, nuclear, or undersea repeater use. 6. The prior written approval of Renesas Technology Corp. is necessary to reprint or reproduce in whole or in part these materials. 7. If these products or technologies are subject to the Japanese export control restrictions, they must be exported under a license from the Japanese government and cannot be imported into a country other than the approved destination. Any diversion or reexport contrary to the export control laws and regulations of Japan and/or the country of destination is prohibited. 8. Please contact Renesas Technology Corp. for further details on these materials or the products contained therein.
RENESAS SALES OFFICES
Renesas Technology America, Inc. 450 Holger Way, San Jose, CA 95134-1368, U.S.A Tel: <1> (408) 382-7500 Fax: <1> (408) 382-7501 Renesas Technology Europe Limited. Dukes Meadow, Millboard Road, Bourne End, Buckinghamshire, SL8 5FH, United Kingdom Tel: <44> (1628) 585 100, Fax: <44> (1628) 585 900 Renesas Technology Europe GmbH Dornacher Str. 3, D-85622 Feldkirchen, Germany Tel: <49> (89) 380 70 0, Fax: <49> (89) 929 30 11 Renesas Technology Hong Kong Ltd. 7/F., North Tower, World Finance Centre, Harbour City, Canton Road, Hong Kong Tel: <852> 2265-6688, Fax: <852> 2375-6836 Renesas Technology Taiwan Co., Ltd. FL 10, #99, Fu-Hsing N. Rd., Taipei, Taiwan Tel: <886> (2) 2715-2888, Fax: <886> (2) 2713-2999 Renesas Technology (Shanghai) Co., Ltd. 26/F., Ruijin Building, No.205 Maoming Road (S), Shanghai 200020, China Tel: <86> (21) 6472-1001, Fax: <86> (21) 6415-2952 Renesas Technology Singapore Pte. Ltd. 1, Harbour Front Avenue, #06-10, Keppel Bay Tower, Singapore 098632 Tel: <65> 6213-0200, Fax: <65> 6278-8001
http://www.renesas.com
(c) 2004. Renesas Technology Corp., All rights reserved. Printed in Japan.
Colophon .1.0


▲Up To Search▲   

 
Price & Availability of M306KAFCLRP

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X